如何更改maven程序集插件生成的war名称

时间:2010-07-16 13:54:53

标签: maven-2

如何将名称从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>

3 个答案:

答案 0 :(得分:155)

maven-assembly-plugin

的配置中使用以下内容
<configuration>
  <finalName>custom-name</finalName>
  <appendAssemblyId>false</appendAssemblyId>
</configuration>

assembly:assembly mojo的官方文档中的完整详细信息。

答案 1 :(得分:88)

您可以通过在pom中指定finalName属性来实现此目的,例如

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

答案 2 :(得分:5)

在使用依赖项打包JAR的情况下,将无效。您将使用依赖项插件修复它:

        <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>