使用 Shade-Plugin 正确最小化 Uber Jar
我正在使用 Maven-Shade-Plugin 创建一个可运行的 Uber-jar。 根据此页面上的最后一帧,可以通过以下方式最小化 jar 的大小:
<configuration>
<minimizeJar>true</minimizeJar>
</configuration>
但此功能不考虑 log4j.properties 文件中声明的类。因此,例如 org.apache.log4j.appender.TimeAndSizeRollingAppender
不包含在 Uber-jar 中,即使它已在 log4j.properties 文件中声明。
我相信Spring也会面临同样的问题。如果我的代码仅引用接口 A 并且我的 Spring 文件包含实现 A 的类 B 的实例化,则 B 可能不会添加到 jar 中,因为它不在代码中。
我该如何解决这个问题?
I am using the Maven-Shade-Plugin to create a runnable Uber-jar.
According to the last frame on this page, the size of the jar can be minimized by using:
<configuration>
<minimizeJar>true</minimizeJar>
</configuration>
But this feature does not take into consideration the classes that are declared in the log4j.properties file. Hence, e.g. org.apache.log4j.appender.TimeAndSizeRollingAppender
is not included in the Uber-jar, even though it’s declared in the log4j.properties file.
I believe I will face the same problem with Spring. If my code only refers to interface A and my Spring file contains an instantiation of class B that implements A, then B might not be added to the jar, since it’s not in the code.
How can I solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此功能已添加到 maven-shade-plugin 1.6 版(刚刚发布)中。现在,minimumJar 将不会删除专门包含在过滤器中的类。请注意,在过滤器中包含某些工件的类将排除该工件的非指定类,因此请务必包含您需要的所有类。
这是一个示例插件配置:
要仅包含特定的类,请在过滤器中的类名中使用路径斜杠将它们添加为包含(同样,未包含的类将被自动排除)。
This functionality has been added to version 1.6 of the maven-shade-plugin (just released). minimizeJar will now not remove classes that have been specifically included with filters. Note that including some of an artifact's classes in a filter will exclude non-specified classes for that artifact, so be sure to include all the classes that you need.
Here's an example plugin config:
To only include specific classes, add them as includes using path slashes in the class name in a filter (again, non-included classes will be automatically excluded).