Maven - 替换 Jar 中的文件
我想在进行 Maven 构建时替换现有 jar/zip 文件中的文件。实现这一目标的最简单方法是什么?
I want to replace a file in an existing jar/zip file while doing a Maven build. What is the easiest way to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于此类任务,我最喜欢的是 maven-antrun-plugin,它为您带来了完整的 ant 功能。
您可以这样使用它:
但请记住 - 永远不要修改本地存储库中的任何文件 - 在此示例中由
${org.apache:common-util:jar}
。这样做会影响您在同一台计算机上进一步构建所有项目(=针对同一本地存储库)。此类构建在其他机器上也是不可重现(或难以重现)的。
My favorite for this sort of tasks is maven-antrun-plugin which brings you complete ant functionality.
You can use it like this:
But remember - never modify any files in your local repository - in this example pointed to by
${org.apache:common-util:jar}
. Doing so would affect your further builds of all your projects on the same computer (= against the same local repo).Such builds are also irreproducible (or hard to reproduce) on other machines.
我不认为有一个专门的插件可以做到这一点,但我想你可以使用 exec 插件 和来自 更新 jar 中的 .class 文件 的信息来完成此操作。
I don't think there is a dedicated plugin to do this but I would imagine you can use the exec plugin and information from Updating .class file in jar to accomplish this.