rcreswick rcreswick - 1 year ago 105
Java Question

Can Maven collect all the dependent JARs for a project to help with application deployment?

I'm just starting to use Maven, (evaluating it, really) and I need to be able to quickly generate a JAR file for my application and a directory with all the dependencies (for example, lib) so that I can deploy those two to be run in a stand-alone manner. Generating the JAR file with the proper manifest is easy, but I do not know how to get Maven to copy the dependencies for the current project into a

directory that I can deploy.

Since this is for a stand-alone Java applications, I am not interested in deploying to a Maven repository, that is also fairly trivial, or at least easily googleable.

I've found out how to do everything except copy the dependent JAR files into some specified directory. This is the workflow I'm looking for:

$ mvn clean
$ mvn package
$ cp -r target/{lib,myApp.jar} installLocation

Then, running
as a JAR file should "just work" regardless of my

To try and pre-empt some answers:

  • I do have a Main-class: set, and it works fine.

  • I've also set the classpath in the MANIFEST.MF, and that works fine too.

  • I've found out how to use
    to make this work -- but only on my machine. (via:

laz laz
Answer Source

What you want to investigate is Maven's dependency plugin. Add something similar to the following to pom.xml:


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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download