使用maven程序集插件覆盖资源文件
我使用 maven- assembly-plugin 和“jar-with-dependencies”来打包 jar。有 2 个具有 log-back.xml 的依赖项工件。第二个工件取决于第一个工件。我希望在最终 jar 中包含第二个工件的 log-back.xml,但它始终包含第一个工件的 log-back.xml。那么我该如何控制呢?
谢谢
I use maven-assembly-plugin with "jar-with-dependencies" to package jar. There are 2 dependencies artifact having log-back.xml. The second artifact is depend on the first one. I want to have log-back.xml of the second artifact in final jar, but it always contain log-back.xml of the first one. So how can I control this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 unpackOptions 来实现此目的。尝试如下操作:
You can use the unpackOptions to achieve this. Try something like the following:
(此时使用最新版本的 maven- assembly-plugin :3.0.0)
我在程序集构建方面遇到了同样的问题。
我有两个具有相同属性文件但内容不同的依赖项(一个好的,另一个用缺少的声明覆盖第一个)。
问题是我最终用错误的配置文件替换了程序集 jar 中的另一个文件。
我发现覆盖该文件的唯一最干净的解决方案是:
1 - 添加我想在项目中构建时保留的好文件:
例如:
src/main/resources/META-INF/services/myfileWhichOverwriteTheBadDependencyRessources.xml
2 - 在我的程序集描述符中添加一个将“filtered”设置为“true”的文件集:(
“project.main.xml”)在我的例子中,“resource”属性设置为“src/main/resources”)
(With last version of maven-assembly-plugin at this time : 3.0.0)
I had the same problem with an assembly build.
I had tow dependencies with the same properties file but with a different content (one good and the other overwritting the first with missing declarations).
The problem was that i finally had the bad configuration file replacing the other in my assembly jar.
The only cleanest solution i found to overwrite the file was to :
1 - Add the good file that i wanted to keep for the build in my project :
ex:
src/main/resources/META-INF/services/myfileWhichOverwriteTheBadDependenciesRessources.xml
2 - Add a fileset with 'filtered' setted to 'true' in my assembly descriptor :
(the 'project.main.resource' property is setted to 'src/main/resources' in my case)
第一个工件是您自己项目的模块吗?如果是这样,您可以排除 pom.xml 的资源部分中的 log-back.xml。
然而,只有当该模块在整个 jar 的范围之外构建时,它本身不需要 log-back.xml 时,这才有效。
Is the first artifact a module of your own project? If so, you could exclude the log-back.xml there in the resources section of the pom.xml.
However, this only works if this module does not require the log-back.xml by itself when it is built out of the scope of the overall jar.