Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Packaging of a Standalone Java program built using Maven [duplicate]

Tags:

java

maven

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?

like image 657
Punter Vicky Avatar asked Aug 27 '26 02:08

Punter Vicky


1 Answers

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)

like image 193
Renato Primavera Avatar answered Aug 29 '26 15:08

Renato Primavera



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!