36

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?

Tuna
  • 2,937
  • 4
  • 37
  • 61
benstpierre
  • 32,833
  • 51
  • 177
  • 288
  • I would recommend using spring profiles (`org.springframework.context.support.PropertySourcesPlaceholderConfigurer`) for variables that change for the application depending on the environment. That way you can build once and redeploy it again in the next environment. This might not be relevant to your case though.. – worldsayshi May 09 '14 at 14:40

3 Answers3

61

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.

Aritz
  • 30,971
  • 16
  • 136
  • 217
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • 2
    Nice tip, but par Maven docs, profiles should not be used to produce a different output. Otherwise, as I've seen, compilations become needlessly complex. – Joseph Lust Nov 04 '12 at 19:49
26

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>
Aritz
  • 30,971
  • 16
  • 136
  • 217
benstpierre
  • 32,833
  • 51
  • 177
  • 288
0

In maven you must use <bundleFileName> in the <module>

You should follow this link to ensure your modules are rewritted: http://maven.apache.org/plugins/maven-ear-plugin/examples/customizing-a-module-filename.html

 <build>
      <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.10.1</version>
                <configuration>
                 [...]
                    <modules>
                        <ejbModule>
                            <groupId>artifactGroupId</groupId>
                            <artifactId>artifactId</artifactId>
                            <bundleFileName>anotherName-1.2.3.jar</bundleFileName>
                        </ejbModule>
                    </modules>
                </configuration>
            </plugin>
        </plugins>
  </build>
David Canós
  • 1,806
  • 18
  • 19