3

Possible Duplicate:
How can I create an executable jar with dependencies using Maven?

I have a standalone java program which is built using Maven. All the dependencies are specified in Maven. When I want to run this standalone java program in a different environment , I will have to copy all the relevant jar files and set it in the classpath. Is this the approach that I must take or is there a better approach available?

Community
  • 1
  • 1
Punter Vicky
  • 15,954
  • 56
  • 188
  • 315
  • duplicate of http://stackoverflow.com/questions/1814526/problem-building-executable-jar-with-maven or http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven – milan Jan 06 '12 at 08:13
  • Thanks milan and oers. Is there any way to close this , so that others wouldn't waste their time? – Punter Vicky Jan 06 '12 at 08:36

1 Answers1

2

Following could maybe help you: when packaging your Java source with Maven, just add the call to the "copy-dependencies" goal of the "dependency" plugin, in this way:

mvn clean package dependency:copy-dependencies

As explained in the Dependency plugin doc at http://maven.apache.org/plugins/maven-dependency-plugin/, this will takes the list of project direct dependencies and optionally transitive dependencies and copies them to a specified location, stripping the version if desired.

By default, all the transitive dependencies will be copied into "target/dependency", making the definition of your classpath very easy.

Another goal called "build-classpath" of the same "dependency" plugin could also help you, by outputting a classpath string of dependencies from the local repository to a file or log (see http://maven.apache.org/plugins/maven-dependency-plugin/build-classpath-mojo.html)