maven 不重新打包依赖项
我使用 Maven 程序集插件将所有依赖项收集到一个 jar 文件中。我怎样才能告诉maven不要重新打包依赖项并将它们作为jar文件包含到生成的jar中?
目前我使用以下插件配置。
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>package.Program</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
想要的 jar 文件结构:
my-jar-with-dependencies.jar
|-dependency1.jar
|-|-class1.class
|-dependency2.jar
|-|-class2.class
|-...........
而不是
my-jar-with-dependencies.jar
|-class1.class
|-class2.class
|-.............
I use maven assembly plugin to collect all dependencies into one jar file. How can I tell maven not to repack dependencies and include them as jar files into resulting jar?
Currently I use following plugin configuration.
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>package.Program</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
wanted structure of jar file:
my-jar-with-dependencies.jar
|-dependency1.jar
|-|-class1.class
|-dependency2.jar
|-|-class2.class
|-...........
and not
my-jar-with-dependencies.jar
|-class1.class
|-class2.class
|-.............
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解了这个问题,您想要指定何时应该运行程序集插件。在这种情况下,您应该考虑创建一个 构建配置文件 并将程序集插件配置添加到新配置文件中。
在 pom.xml 中添加:
当您希望 maven 运行程序集插件时,您可以使用 -P 开关切换到“mvn”脚本,如下所示:
If I understand the question correctly you want to specify when the assembly plugn should be run or not. I this is the case you should consider creating a build profile and add the assembly plugin configuration to the new profile.
In pom.xml add:
When you want maven to run the assembly plugin you can then use the -P switch to the 'mvn' script like this: