如何从 Maven 项目创建独立的 jar?
我正在尝试创建一个独立的 jar 文件,我认为 Maven 包没有正确地将我的依赖项打包到包中。有没有办法强制它包含它们?
I am trying to create a standalone jar file I don't think that maven package
is properly packaging my dependencies into the package. Is there a way to force it to include them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
或者,您可以使用 jar-with-dependencies maven 程序集插件的打包。
Alternately you could use the jar-with-dependencies packaging of maven assembly plugin.
您需要使用 shade 插件。
默认情况下,maven 构建并打包当前项目的编译输出。阴影插件允许您创建一个“uber”jar,它不仅包含您的代码,还包含所有依赖项到一个(有时相当大)jar 中。
(可选)允许您在打包中重新定位类阶段,这意味着您的项目可以拥有其依赖项的完全私有副本,而不会陷入 jar 地狱。
You need to use the shade plugin.
By default maven builds and packages the compile output from the current project. The shade plugin allows to you create an 'uber' jar that contains not just your code but all of the dependencies into a single (sometimes quite big) jar.
Optionally allows you to relocate classes in the packaging phase, meaning that your project can have completely private copies of it's dependencies without getting caught in jar hell.
您可以在此处找到有关如何使用 Maven 程序集插件的基本示例。
您只需要克隆存储库
并运行 mvn package
You can find an a basic example on how to use the maven assembly plugin here.
You need only to clone the repository
and run mvn package
请检查此答案https://stackoverflow.com/a/35359756/5678086以创建包含所有依赖项的完整包
Please check this answer https://stackoverflow.com/a/35359756/5678086 for creating full pack with all dependencies