jar-with-dependencies Maven Assembly

时间:2011-03-11 16:57:15

标签: maven-2 maven maven-3 maven-assembly-plugin

我创建了一个简单的Maven项目(Packaging type-Jar),该项目依赖于Spring和My Sql库(mysql-connector)。当我用$mvn package打包这个项目时,我在成功执行此命令后得到一个jar文件。

我还试图在输出jar文件中包含所有依赖项,所以我添加了一个'jar-with-dependencies'程序集描述符,但正如文档所说:

The `jar-with-dependencies` descriptor builds a JAR archive with the contents of the main project jar along with the unpacked contents of all the project’s runtime dependencies. 

我希望以JAR形式包含依赖项,而不是unpacked方式。我怎么能这样做?

3 个答案:

答案 0 :(得分:4)

Java无法从jar中的jar中加载类。您必须使用one-jarmaven plugin等项目对其进行配置。

答案 1 :(得分:2)

也许这有助于Maven Shade Plugin:Maven Excecutable Jar

奥利弗

答案 2 :(得分:0)

Vicky试图聚集罐子,这就像Maven所说的那样被称为“building-an-aggregate-jar”。您可以在Robert的[1]和Artifact Technical Notes [2]博客中找到更多信息。 一个讨论[3]也可以提供帮助。

此致

[1] http://rombertw.wordpress.com/2010/05/14/maven-recipe-building-an-aggregate-jar/

[2] http://blog.artifact-software.com/tech/?p=121

[3] http://maven.40175.n5.nabble.com/Aggregate-POM-for-thirdparty-package-dependencies-not-downloaded-td113927.html

相关问题