使用 Maven 在 jar 中包含依赖项 [英] Including dependencies in a jar with Maven
问题描述
有没有办法强制 maven(2.0.9) 在单个 jar 文件中包含所有依赖项?
Is there a way to force maven(2.0.9) to include all the dependencies in a single jar file?
我有一个项目,它构建到一个单独的 jar 文件中.我也希望将依赖项中的类复制到 jar 中.
I have a project the builds into a single jar file. I want the classes from dependencies to be copied into the jar as well.
更新:我知道我不能只在 jar 文件中包含一个 jar 文件.我正在寻找一种方法来解压指定为依赖项的 jar,并将类文件打包到我的 jar 中.
Update: I know that I cant just include a jar file in a jar file. I'm searching for a way to unpack the jars that are specified as dependencies, and package the class files into my jar.
推荐答案
您可以使用带有jar-with-dependencies"描述符的 maven-assembly 插件来做到这一点.这是我们的 pom.xml 中执行此操作的一个相关块:
You can do this using the maven-assembly plugin with the "jar-with-dependencies" descriptor. Here's the relevant chunk from one of our pom.xml's that does this:
<build>
<plugins>
<!-- any other plugins -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
这篇关于使用 Maven 在 jar 中包含依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!