Can Maven collect all the dependent JARs for a project to help with application deployment?
Solution 1:
What you want to investigate is Maven's dependency plugin. Add something similar to the following to pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<outputDirectory>
${project.build.directory}
</outputDirectory>
</configuration>
</plugin>
Then run mvn clean dependency:copy-dependencies
to copy perform the copy. Combine this with the assembly plugin and you can package everything into a self contained archive for distribution.
Solution 2:
I did not care for the Shade plugin since it rolls all the packages from all the jars together.
To include all of the external libs you can use the Dependency Plugin as mentioned above.
This example will create a "lib" directory under "target/classes" before the "package" phase.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.6</version> <executions> <execution> <id>copy-dependencies</id> <phase>prepare-package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>target/classes/lib</outputDirectory> <overWriteIfNewer>true</overWriteIfNewer> <excludeGroupIds> junit,org.hamcrest,org.mockito,org.powermock,${project.groupId} </excludeGroupIds> </configuration> </execution> <execution> <phase>generate-sources</phase> <goals> <goal>sources</goal> </goals> </execution> </executions> <configuration> <verbose>true</verbose> <detail>true</detail> <outputDirectory>${project.build.directory}</outputDirectory> </configuration> </plugin>
Solution 3:
Take a look at maven's dependency plugin, specifically the copy-dependencies goal. The usage section describes how to do exactly what you want.
To do it from the command line just do:
$ mvn dependency:copy-dependencies -DoutputDirectory=OUTPUT_DIR
Solution 4:
Yet another one is appassembler plugin
What I like about it is that it packages the app in a form ready to use (with a .bat file ans such)