我試圖通過使用Maven Shade Plugin
的minimizeJar
來最小化UberJar的大小。它看起來像minimizeJar
只包括在代碼中靜態導入的類(我懷疑這是因爲我看到LogFactory.class
在超級罐子裏org\apache\commons\logging\
但沒有包括impl
包的類,因此在運行超級罐時拋出java.lang.ClassNotFoundException: org.apache.commons.logging.impl.LogFactoryImpl
)。配置Maven Shade最小化Jar包含類文件
有沒有什麼辦法可以告訴Maven的Shade插件將指定的軟件包包含到最終的jar中?無論minimizeJar
暗示什麼?
這裏我想做的POM片段:
<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/**/*'。 – Corubba 2012-01-02 12:00:59
按照你的建議,我嘗試了'... logging/**','... logging/**/*','... logging /**/*.*',但都沒有成功。我想問題是包括首先包括然後最小化Jar忽略其他所有和捆綁罐子,因爲它認爲是合適的。 – kunal 2012-01-02 13:24:49