将 jar 打包到具有分离的外部资源和依赖项的 dist 目录中
这就是我想要实现的目标 - 一个 dist
目录(或一个 zip 文件),如下所示:
dist/
|-- application-1.0.jar
|-- conf/
|-- application.properties
|-- log4j.properties
|-- lib/
|-- *.jar
基本上:
- 生成了一个可执行 jar(在清单中具有适当的类路径)
- 我想排除 < code>src/main/resources 自动与 jar 一起打包,以便可以修改
application.properties
- 我希望在
lib/
中有外部依赖项> 目录
我想出了一个使用配置文件并将插件附加到包阶段的解决方案,但是使用程序集插件会是更好的解决方案吗?
Here's what I'm trying to achieve - a dist
directory (or a zip file) that looks like this:
dist/
|-- application-1.0.jar
|-- conf/
|-- application.properties
|-- log4j.properties
|-- lib/
|-- *.jar
Basically:
- An executable jar is produced (with appropriate classpath in the manifest)
- I want to exclude
src/main/resources
from being automatically packaged with the jar, so thatapplication.properties
can be modified - I want to have external dependencies in the
lib/
directory
I came up with a solution using a profile with plugins attached to the package phase, but would using the assembly plugin be a better solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用程序集插件的解决方案分为几个部分:
maven-jar-plugin
)和配置程序集插件(maven-assemble-plugin
) >)。distribution-zip.xml
) 定义的 zip 文件中。在 pom 中,配置插件:
程序集文件
distribution-zip.xml
的内容(感谢 Neeme Praks) 组合了创建的 jar、资源和依赖项:生成的可分发 zip 文件是创建方式类似于
target/killer-app-1.0-dist.zip
!The solution using the assembly plugin has a few parts:
maven-jar-plugin
), and configuring the assembly plugin (maven-assembly-plugin
).distribution-zip.xml
).In the pom, configure the plugins:
The contents of the assembly file
distribution-zip.xml
(with thanks to Neeme Praks) combines the created jar, resources and dependencies:The resulting distributable zip file is created like
target/killer-app-1.0-dist.zip
!您需要使用两个插件来完成此操作:maven-jar-plugin 和 maven-assemble-plugin。
有用的
pom.xml
示例:(我建议您将用户可编辑的属性文件放置在单独的目录中,但这只是个人喜好的问题。)
示例程序集配置,帮助您入门:
You need to use two plugins to accomplish this: maven-jar-plugin and maven-assembly-plugin.
Useful
pom.xml
samples:(I would recommend you to separate the user-editable properties files to separate directory, but it is a matter of taste.)
Sample assembly configuration, to get you started: