0

I have a requirement to merge some jar into a common jar using maven. My system looks like as follows

first 
    |_ out 
        |-- jar1.jar
        |-- jar2.jar

second
    |--out
        |-- jar3.jar
        |-- jar4.jar

I wants to merge those 4 jar into one jar and place them in

first 
    |-- out
            |-- msg

I tried to use maven-shade plugin but I am not sure how to provide the path to those jar

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <minimizeJar>true</minimizeJar>
              <filters>
                <filter>
                   <artifact>jar1:jar1</artifact>
                   <includes>
                       <include>**</include>
                   </includes>
                </filter>
                <filter>
                   <artifact>jar2:jar2</artifact>
                   <includes>
                       <include>**</include>
                   </includes>
                </filter>
                <filter>
                   <artifact>jar4:jar4</artifact>
                   <includes>
                       <include>**</include>
                   </includes>
                </filter>
                <filter>
                   <artifact>jar3:jar3</artifact>
                   <includes>
                       <include>**</include>
                   </includes>
                </filter>
              </filters>            
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

If there is any other way I am open for that.

Ashish
  • 14,295
  • 21
  • 82
  • 127

1 Answers1

0

You can't put jar files into another jar file, -jar files don't work that way. What you need is for all of the contents of all of the jar files to be extracted, and then zipped up again into one jar.

Edit :
<include> : instruct it what dependencies to pull into the uber JAR

<include>groupId:artifactId</include>

<excludes>: excludes some stuff from the target JAR that shouldn't be in there - such as JAR metadata, ant build files, text files, etc

something like this

 <configuration>
    <minimizeJar>true</minimizeJar>
      <artifactSet>
         <includes>
            <include>com.google.guava:guava</include>
            <include>net.sf.trove4j:trove4j</include>
            <include>org.mvel:mvel2</include>
            <include>com.fasterxml.jackson.core:jackson-core</include>
            <include>joda-time:joda-time</include>
          </includes>
        </artifactSet>
        <filters>
           <filter>
              <artifact>*:*</artifact>
                <excludes>
                    <exclude>META-INF/license/**</exclude>
                    <exclude>META-INF/*</exclude>
                    <exclude>META-INF/maven/**</exclude>
                    <exclude>LICENSE</exclude>
                    <exclude>NOTICE</exclude>
                    <exclude>/*.txt</exclude>
                    <exclude>build.properties</exclude>
                </excludes>
            </filter>
        </filters>
 </configuration>
SparkOn
  • 8,806
  • 4
  • 29
  • 34
  • How can I achieve this using maven ? – Ashish Aug 12 '14 at 18:19
  • if they are module jar's have a look at maven-shade-plugin or maven-assembly-plugin have a look at this [question](http://stackoverflow.com/questions/1832853/is-it-possible-to-create-an-uber-jar-containing-the-project-classes-and-the-pr) – SparkOn Aug 12 '14 at 18:23
  • I am trying to use maven-shade-plugin but I am not sure how to point to the jar to be included. – Ashish Aug 12 '14 at 18:42