Friday, 8 May 2015

Create Multiple Jars from single pom.xml in Maven

Note : It is recommended to create a single from one pom. If possible then try to decompose the package structure to create multiple projects and create one jar for one project. If it is not helpful then use the below process to create multiple jars from single pom.


<plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>

          <execution>
            <id>any_Id</id>
            <goals><goal>jar</goal></goals>
            <phase>package</phase>
            <configuration>
<finalName>JarOne</finalName>
                <encoding>ISO-8859-1</encoding>
                <classifier>Core</classifier> <!-- This will be appended with the jar created with finalName tag value if present-->
               <includes>
<include>**/*.*</include>              
              </includes>
              <excludes>
                          <exclude>**/test.*</exclude>
              </excludes>  
            </configuration>
          </execution>

 <execution>
            <id>any_Id</id>
            <goals><goal>jar</goal></goals>
            <phase>package</phase>
            <configuration>
<finalName>JarOne</finalName>
                <encoding>ISO-8859-1</encoding>
                <classifier>NonCore</classifier> <!-- This will be appended with the jar created-->
               <includes>
<include>**/*.*</include>              
              </includes>
              <excludes>
                          <exclude>**/test.*</exclude>
              </excludes>  
            </configuration>
          </execution>

 </executions>
</plugin>

Create more than one <execution> to create individual jars. The names of the jars will be appended with the value of <classifier> tag. If you are including <finalName> tag then the jar name will be as follows.

JarOne-Core.jar
JarOne-NonCore.jar


No comments:

Post a Comment

Thank You for your valuable comment

Difference between class level and object locking and static object lock

1) Class level locking will lock entire class, so no other thread can access any of other synchronized blocks. 2) Object locking will lo...