Thursday, September 04, 2014

Creating jar with dependencies in Maven Project

Simple but quite useful :

Simple add this in your pom.xml and run mvn package or install


<!--  create jar with dependencies -->
 <build>
  <plugins>
  <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
   <configuration>
   <archive>
    <manifest>
     <mainClass>fully.qualified.MainClass</mainClass>
    </manifest>
   </archive>
   <descriptorRefs>
    <descriptorRef>jar-with-dependencies</descriptorRef>
   </descriptorRefs>
  </configuration>
   <executions>
   <execution>
     <id>make-assembly</id><!-- this is for inheritance merges -->
     <phase>package</phase> <!-- bind to the packaging phase -->
    <goals>
     <goal>single</goal>
    </goals>
   </execution>
  </executions>
   </plugin>
  </plugins>
 </build>

No comments: