Packaging of a Standalone Java program built using 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?


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)

链接地址: http://www.djcxy.com/p/29628.html

上一篇: Maven可执行文件Jar在启动时抛出错误

下一篇: 打包使用Maven构建的独立Java程序