Java:如何构建基于Maven的项目的独立发行版? [英] Java: How do I build standalone distributions of Maven-based projects?

查看:159
本文介绍了Java:如何构建基于Maven的项目的独立发行版?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常遇到Java应用程序或库的发行版,其中
使用Maven作为他们的构建工具。

I often encounter distributions of Java applications or libraries which use Maven as their build tool.

其中一些,遗憾的是,它们不提供独立的(或可再分发的)jar。

Some of them, sadly, don't provide standalone (or redistributable) jars.

是否可以以这种方式构建基于Maven的应用程序, b 构建结果包含所有依赖项并且可以重新分配以开箱即用?

Is it possible to build Maven-based applications in such a way, that the build result contains all dependencies and can be redistributed to work out-of-the box?

我试图构建Jackrabbit的OCM模块。
由于一些非常智能的原因,没有可下载的独立
版本。

所以我用Maven构建了Jackrabbit(Jackrabbit的源包包括
OCM),以及得到了与 apache存储库
jar 包含必要的依赖项,对我来说无用

I tried to build Jackrabbit's OCM module. For some very "intelligent" reasons there is no downloadable standalone version.
So I built Jackrabbit with Maven (the source package of Jackrabbit includes OCM), and got the same jar as found in the apache repository. The jar doesn't contain necessary dependencies and is useless to me.

推荐答案

使用Maven Shade插件

...但要小心陷阱(类似于我的答案中进一步描述的那个),这已经得到了这里解释的解决方法

...but be careful of the gotchas (similar to the one described further down my answer), which has got a workaround explained here.

另外,要小心谨慎Shade插件配置。我不小心使用了双< configuration> 标签一次,而变形金刚根本没有应用,插件也冒昧地不警告我。

Also, be ultra careful with the Shade plugin config. I accidentally used double <configuration> tags once, and the transformers didn't apply at all, and the plugin also took the liberty of not warning me.

不要使用Maven Assembly插件

程序集:单个将按原样解压缩依赖JAR,这可能不是您想要的。例如。像 META-INF / spring.schemas 这样的东西会被评估的最后一个Spring依赖JAR覆盖,因此你的XSD将无法找到(除了那些之外)最后的JAR,当然)。这就是为什么像Alfresco这样的系统制作了他们的AMP插件,它在您正在构建的AMP中捆绑了 lib / 内的依赖项。然而,后者引发了依赖管理问题。

assembly:single will unpack your dependency JARs as-is, and this could not be what you want. E.g. stuff like META-INF/spring.schemas will be overridden with the last Spring dependency JAR that's evaluated, and as such your XSDs won't be found (apart from those in the last JAR, of course). Which is why systems like Alfresco made their AMP plugin which bundles dependencies inside lib/ inside the AMP you're building. The latter raises dependency management issues, though.

这篇关于Java:如何构建基于Maven的项目的独立发行版?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆