问题描述
我有一个生成 jar 文件的 Maven 模块.我被要求开发一些其他的 uberjar 文件作为构建过程的副产品.我还被告知这 2 个 jar 文件是小程序 jar 文件将需要包含来自 maven 模块依赖项的一些类.
I have a maven module generating a jar file. I have been asked to develop a couple of other uberjar filesas a byproduct of build process. I have also been told these 2 jar files are applet jar files thatwill be need include some classes from the dependencies of the maven module.
我环顾四周,缩小到这 3 个选项 -
I looked around and narrowed down to these 3 options -
- Maven Assembly插件 - 这可以从生成的类构建自定义jar通过 maven 模块.不能包含第三方依赖项.
- 通过Maven使用ant - 使用maven-dependency-plugin解压依赖,然后通过 ant 脚本打包小程序 jar.
- 使用Maven shade插件 - 虽然这个插件不直接适合我的要求,我可以让它工作.
- Maven Assembly plugin - This can build custom jars from the classes generated by the maven module. Third party dependencies cant be included.
- Use ant through Maven - Use maven-dependency-plugin to unpack dependencies and then pack the applet jars through ant scripts.
- Use Maven shade plugin - Although this plugin is not directly suited for my requirement, I can get it working.
虽然我可以使用 (b) 和 (c) 解决问题,但我无法决定使用哪一个.我注意到的一件事是使用依赖插件非常耗时.
While I can get things working with (b) and (c), I am unable to decide which one to use. One key thing I have noticed is using the dependency plugin is time consuming.
我想知道人们是否还有其他方法可以实现相同的要求.
I wanted to know if there are other ways people achieve the same requirement.
推荐答案
您可以使用带有 dependencySet
元素的程序集插件包含依赖项,请参阅:
You can include dependencies using the assembly plugin with the dependencySet
elements, see:
具体来说,这里有一个来自 Andrew E Bruno 的例子博客:
Specifically here's an example taken from Andrew E Bruno's blog:
<dependencySets>
<dependencySet>
<outputDirectory></outputDirectory>
<outputFileNameMapping></outputFileNameMapping>
<unpack>true</unpack>
<scope>runtime</scope>
<includes>
<include>commons-lang:commons-lang</include>
<include>commons-cli:commons-cli</include>
</includes>
</dependencySet>
</dependencySets>
这篇关于maven - 如何构建具有依赖项的 uberjars的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!