Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In maven - how to rename the output .war file based on the name of the profile in use

Tags:

maven

war

I have three profiles in my pom.xml for our application...

  1. dev (for use on a developer's)
  2. qa (for use on our internal qa server)
  3. prod (production).

When we run our maven build all three profiles ouput a war file with the same name. I would like to output $profilename-somearbitraryname.war

Any ideas?

like image 862
benstpierre Avatar asked May 25 '11 19:05

benstpierre


People also ask

Can we rename a WAR file?

You can rename the WAR file if you are using a WAR file for deployment, and you want to use "Workplace XT" or a custom name for the context root of the application.

Can we rename POM XML?

Maven looks for the pom. xml file, so you should rename it that for it to work. You could use another file name using the -f option. mvn -f parent-pom.


1 Answers

You've answered yourself correctly:

<profiles>     <profile>         <id>dev</id>         <properties>             <rp.build.warname>dev</rp.build.warname>         </properties>     </profile>     <profile>         <id>qa</id>         <properties>             <rp.build.warname>qa</rp.build.warname>         </properties>     </profile>     <profile>         <id>prod</id>         <properties>             <rp.build.warname>prod</rp.build.warname>         </properties>     </profile> </profiles> 

but there is a simpler way to redefine WAR name:

<build>     <finalName>${rp.build.warname}-somearbitraryname</finalName>     <!-- ... --> </build> 

No maven-war-plugin is needed.

like image 138
Tomasz Nurkiewicz Avatar answered Sep 21 '22 14:09

Tomasz Nurkiewicz