如何更改由 maven 汇编插件生成的战争名称

如何将名称从 1.0.snapshot-jar-with-dependencies更改为其他名称,下面是我的 POM 的内容:

<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<archive>
<manifest>
<mainClass>com.package.example.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
83023 次浏览

You can achieve this by specifying the finalName property in your pom, e.g.

<build>
<finalName>something-else</finalName>
...
</build>

Use the following in the configuration of the maven-assembly-plugin:

<configuration>
<finalName>custom-name</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>

Full details in the official documentation of the assembly:single mojo.

In the case of packaging a JAR with dependencies, the won't work. You will fix it by using the dependency plugin:

        <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>project.group.id</groupId>
<artifactId>artifact-id</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${basedir}/some/dir</outputDirectory>
<destFileName>custom-name.jar</destFileName>
</artifactItem>
</artifactItems>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>