我正在使用 Maven 程序集插件。在我的 pom.xml 中,打包类型:jar 并且我不使用 maven jar 插件。
每当我运行 mvn clean package 时,它都会创建 2 个 jar 文件:一个来自 Maven 程序集,另一个是默认创建的(由于打包类型 =jar)。我只想保留仅由程序集插件创建的 jar 文件。如何做到这一点?
你可能有你的理由,但我怀疑跳过正在构建和部署的默认 jar 是一个好的解决方案。
无论如何,这里是如何禁用正在构建的默认 jar。
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<id>make-assembly</id>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- some configuration of yours... -->
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-jar</id>
<!-- put the default-jar in the none phase to skip it from being created -->
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
我偶然发现了同样的问题,并通过添加一个子句将最初创建的
<xyz>.jar
(不包含依赖项)重命名为 <xyz>.jar.original
(当然,人们可能也想立即删除它)来“解决”它。 。我的 pom 创建的第二个 jar 文件(也包含所有依赖项)始终命名为 <xyz>-jar-with-dependencies.jar
,我现在将其重命名为 <xyz>.jar
。这样,包含所有依赖项的 jar 就具有我想要的名称,并且原始名称已移开。
YMMV...
...
<plugin> <!-- found this solution here: https://stackoverflow.com/questions/5016467/only-create-executable-jar-with-dependencies-in-maven:
instead of avoiding the creation of the default.jar we rename it and rename the 'jar-with-dependencies' as well -->
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>rename-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<move
file="${project.build.directory}/${project.build.finalName}.jar"
tofile="${project.build.directory}/${project.build.finalName}.jar.original" />
<move
file="${project.build.directory}/${project.build.finalName}-jar-with-dependencies.jar"
tofile="${project.build.directory}/${project.build.finalName}.jar" />
</target>
</configuration>
</execution>
</executions>
</plugin>
...