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

前端 未结 3 1185
南方客
南方客 2020-12-13 09:48

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 (produ
相关标签:
3条回答
  • 2020-12-13 10:13

    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>
    
    0 讨论(0)
  • 2020-12-13 10:14

    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>
    
    0 讨论(0)
  • 2020-12-13 10:21

    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.

    0 讨论(0)
提交回复
热议问题