Home Navigation

Sunday 3 December 2017

Maven: How to create multiple jars from a single maven project ( maven-jar-plugin)

Two produce multiple jars from a single module project you may use maven-jar-plugin. It is pretty simple to use. In prepare-package phase under configuration you can put your configuration.

below a sample xml file.

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>build-business-jar</id>
<phase>prepare-package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<archive>
<manifestFile>${basedir}/META-INF/MANIFEST.MF</manifestFile>
</archive>
<includes>
<include>com/**/*</include>
<include>**/*.xml</include>
</includes>
<excludes>
<exclude>com/exclude4/**/*</exclude>
</excludes>
<finalName>jarfilename2</finalName>
</configuration>
</execution>
<execution>
<id>build-webservices-jar</id>
<goals>
<goal>jar</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<includes>
<include>com/walmart/**/*</include>
<include>**/*.xml</include>
</includes>
<excludes>
<exclude>com/exclude1/**/*</exclude>
<exclude>com/exclude2/**/*</exclude>
<exclude>com/exclude3/**/*</exclude>
</excludes>
<finalName>jarfilename2</finalName>
</configuration>
</execution>
</executions>

</plugin>

No comments:

Post a Comment