Monday, December 1, 2014

Packaging All JARS with Maven Plugin

A description of the build lifecycle of Maven can be found at maven.apache.org.

When executing a command such as

call mvn -e deploy -DskipTests=true

You may want to include all the dependencies into the jar itself.

You may add this plugin to your pom.xml file in the <project><build><plugins> section (copied from stackoverflow.com).

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>
    </configuration>
  </plugin>

If you do this, the maven-assemply-plugin will execute the jar-with-dependencies during the package phase. You should then see two jars in your Maven repository. One will have a suffix like '-jar-with-dependencies.jar'.

No comments:

Post a Comment