【发布时间】:2012-01-31 16:45:59
【问题描述】:
我正在尝试使用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 时)。
无论minimizeJar 建议什么,我有什么方法可以告诉 Maven 的 Shade 插件将指定的包包含到最终的 jar 中?
这里是我正在尝试的 pom sn-p:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<filters>
<filter>
<artifact>commons-logging:commons-logging</artifact>
<includes>
<include>org/apache/commons/logging/**</include>
</includes>
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.myproject.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
【问题讨论】:
-
org/apache/commons/logging/**只匹配目录,你可能想匹配所有文件。请改用org/apache/commons/logging/**/*。 -
按照您的建议,我尝试了
...logging/**、...logging/**/*、...logging/**/*.*,但都没有奏效。我想问题是首先包含 include 然后 minimizeJar 忽略其他所有内容并按照它认为合适的方式捆绑 jar。