Maven: How to rename the war file for the project?

JavaMaven

Java Problem Overview


I have a project bird with the following components in pom.xml

   <groupId>com.myorg</groupId>
    <artifactId>bird</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>bird</name>

    <modules>
        <module>persistence</module>
        <module>business</module>
        <module>service</module>
        <module>web</module>
    </modules>

and the web module pom.xml

   <parent>
        <artifactId>bird</artifactId>
        <groupId>com.myorg</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>web</artifactId>
    <packaging>war</packaging>  

The web module creates a war file named web-1.0-SNAPSHOT.war
How can I configure maven to build it as bird.war?

Java Solutions


Solution 1 - Java

You can use the following in the web module that produces the war:

<build>
  <finalName>bird</finalName>
 . . .
</build>

This leads to a file called bird.war to be created when goal "war:war" is used.

Solution 2 - Java

You need to configure the war plugin:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <warName>bird.war</warName>
        </configuration>
      </plugin>
    </plugins>
  </build>
  ...
</project>

More info here

Solution 3 - Java

Lookup pom.xml > project tag > build tag.

I would like solution below.

<artifactId>bird</artifactId>
<name>bird</name>
    
<build>
    ...
    <finalName>${project.artifactId}</finalName>
  OR
    <finalName>${project.name}</finalName>
    ...
</build>

Worked for me. ^^

Solution 4 - Java

You can follow the below step to modify the .war file name if you are using maven project.

Open pom.xml file of your maven project and go to the tag <build></build>,

  1. In that give your desired name between this tag : <finalName></finalName>.

    ex. : <finalName>krutik</finalName>

After deploying this .war you will be able to access url with:
http://localhost:8080/krutik/

  1. If you want to access the url with slash '/' then you will have to specify then name as below:

    e.x. : <finalName>krutik#maheta</finalName>

After deploying this .war you will be able to access url with:
http://localhost:8080/krutik/maheta

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondaydreamerView Question on Stackoverflow
Solution 1 - JavaSébastien Le CallonnecView Answer on Stackoverflow
Solution 2 - JavaAndres OlarteView Answer on Stackoverflow
Solution 3 - JavabamosszaView Answer on Stackoverflow
Solution 4 - JavaKrutikView Answer on Stackoverflow