In maven - how to rename the output .war file based on the name of the profile in use
60,111
Solution 1
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.
Solution 2
The answer was simple...
Define a property in each profile like this...
<profile>
<id>qa</id>
<properties>
<rp.build.warname>ourapp-qa</rp.build.warname>
</properties>
</profile>
Then add this to your plugins...
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<packagingExcludes>WEB-INF/web.xml</packagingExcludes>
<warName>${rp.build.warname}</warName>
</configuration>
</plugin>
![benstpierre](https://i.stack.imgur.com/tZgrA.jpg?s=256&g=1)
Author by
benstpierre
My entire career has been building commercial software mostly in Java and C#. I have working with a dozen other languages but I really love working in these two the most. Recently I have been writing application in Vaadin and think it's the best thing since sliced bread.
Updated on November 24, 2020Comments
-
benstpierre over 3 years
I have three profiles in my pom.xml for our application...
- dev (for use on a developer's)
- qa (for use on our internal qa server)
- 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?