打包使用Maven构建的独立Java程序 [英] Packaging of a Standalone Java program built using Maven
问题描述
Possible Duplicate:
How can I create an executable jar with dependencies using Maven?
我有一个使用Maven构建的独立Java程序.所有依赖项都在Maven中指定.当我想在不同的环境中运行这个独立的Java程序时,我将必须复制所有相关的jar文件并将其设置在类路径中.这是我必须采取的方法还是有更好的方法可用?
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?
推荐答案
以下内容可能会为您提供帮助:用Maven打包Java源代码时,只需将调用添加到依赖项"插件的复制依赖项"目标中,通过这种方式:
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
如Dependency插件文档中 http://maven.apache.org所述/plugins/maven-dependency-plugin/,它将获取项目直接依赖项列表以及可选的传递性依赖项列表,并将它们复制到指定位置,并在需要时剥离版本.
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.
通过将本地存储库中的依赖项的类路径字符串输出到文件或日志中,同一依赖项"插件的另一个目标"build-classpath"也可以为您提供帮助(请参见
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)
这篇关于打包使用Maven构建的独立Java程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!