我正在尝试通过使用Maven Shade插件的
有没有办法告诉Maven Shade插件将指定的包包含到最终的jar中,无论
这是我尝试的pom片段:
minimizeJar
来最小化UberJar的大小。看起来minimizeJar
只包括代码中静态导入的类(我怀疑这是因为我在uber jar中看到了org\apache\commons\logging\LogFactory.class
,但没有包含impl
包中的任何类,因此在运行uber-jar时会抛出java.lang.ClassNotFoundException: org.apache.commons.logging.impl.LogFactoryImpl
)。有没有办法告诉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...logging/**
、...logging/**/*
和...logging/**/*.*
,但都没有起作用。我猜问题在于包含文件先被包含,然后 minimizeJar 忽略其他所有内容,并将 jar 打包为它认为合适的形式。 - kdabir