In maven - how to rename the output .war file base

2019-01-21 22: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?

回答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.



回答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>


回答3:

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>


标签: maven war