How can I change the war name generated by maven assembly plugin

喜夏-厌秋 提交于 2019-12-18 10:20:04

问题


How can I change the name from 1.0.snapshot-jar-with-dependencies to something else, below are contents of my 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>

回答1:


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.




回答2:


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

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



回答3:


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>


来源:https://stackoverflow.com/questions/3265544/how-can-i-change-the-war-name-generated-by-maven-assembly-plugin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!