配置Maven Shade minimizeJar以包含类文件
我试图通过使用Maven Shade Plugin
的minimizeJar
来最小化UberJar的大小。 看起来minimizeJar
只包含在代码中静态导入的类(我怀疑这是因为我在org\apache\commons\logging\
中的uber jar中看到了LogFactory.class
,但是没有包含impl
包的类,因此抛出java.lang.ClassNotFoundException: org.apache.commons.logging.impl.LogFactoryImpl
当我运行uber-jar时, java.lang.ClassNotFoundException: org.apache.commons.logging.impl.LogFactoryImpl
。
有什么方法我可以告诉Maven的Shade插件将指定的包包含到最终的jar中,无论minimizeJar
建议什么?
这是我正在尝试的pom片段:
org.apache.maven.plugins maven-shade-plugin 1.5 package shade true commons-logging:commons-logging org/apache/commons/logging/** com.myproject.Main
此function已添加到maven-shade-plugin的1.6版本(刚刚发布)。 minimizeJar现在不会删除filter中特别包含的类。 请注意,在filter中包含一些工件的类将排除该工件的非指定类,因此请确保包含所需的所有类。
这是一个示例插件配置:
org.apache.maven.plugins maven-shade-plugin 1.6 package shade true log4j:log4j ** commons-logging:commons-logging **
我正在使用Maven Shade插件的2.0版本,但仍然无法在“最小化”JAR之后包含类。
作为一种解决方法,我唯一想到的就是创建对所需类的引用,以避免最小化代码摆脱它们。 即:
/* * This block prevents the Maven Shade plugin to remove the specified classes */ static { @SuppressWarnings ("unused") Class>[] classes = new Class>[] { JButton.class, JMenu.class, JMenuBar.class, JMenuItem.class }; }
我希望Maven开发人员能够实现一种处理这种情况的方法(我猜这很常见)。