实际上,我没有检查它到底在maven-shade-plugin
做什么(或任何其他插件),因为maven 2具有内置的所有功能来创建megaja
r或uberjar
。你只需要使用带有预定义jar-with-dependencies
描述符的maven-assembly-plugin
即可。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>my.package.to.my.MainClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
然后以下命令将生成你的uberjar
:
mvn assembly:assembly -DdescriptorId=jar-with-dependencies
但是,同样,此描述符的默认行为是解压缩依赖项(例如maven-shade-plugin)。老实说,我不明白为什么会出现这个问题,但是,如果这不是你想要的,那么你可以使用自己的自定义程序集描述符。
为此,首先,创建src/assembly/uberjar.xm
l具有以下内容的程序集描述符:
<assembly>
<id>uberjar</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>false</unpack>
<scope>runtime</scope>
<useProjectArtifact>false</useProjectArtifact>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>
然后,配置maven-assembly-plugin以使用此描述符,并将依赖Class-Path项添加到清单的条目中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/assembly/uberjar.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>my.package.to.my.MainClass</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
<!--
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
-->
</plugin>
最终运行mvn assembly:assembly以生成你的uberjar。