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

北城余情 提交于 2019-11-28 17:49:45
Tomasz Nurkiewicz

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.

benstpierre

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>

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>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!