daydreamer
daydreamer

Reputation: 92139

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

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?

Upvotes: 127

Views: 136805

Answers (5)

Gayan Mettananda
Gayan Mettananda

Reputation: 1518

Within the <build> tag specify the name that you need for the war file as "finalName".

<build>
    <finalName>${project.artifactId}</finalName>
</build>

Upvotes: 0

bamossza
bamossza

Reputation: 3926

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

Upvotes: 14

Krutik
Krutik

Reputation: 1207

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/

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

Upvotes: 6

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.

Upvotes: 260

Andres Olarte
Andres Olarte

Reputation: 4380

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

Upvotes: 34

Related Questions