【问题标题】:In maven - how to rename the output .war file based on the name of the profile in use在 Maven 中 - 如何根据正在使用的配置文件的名称重命名输出 .war 文件
【发布时间】:2011-09-02 01:01:11
【问题描述】:

我的 pom.xml 中有三个配置文件用于我们的应用程序...

  1. dev(供开发人员使用)
  2. qa(用于我们的内部 qa 服务器)
  3. 产品(生产)。

当我们运行我们的 maven 构建时,所有三个配置文件都会输出一个同名的 war 文件。我想输出$profilename-somearbitraryname.war

有什么想法吗?

【问题讨论】:

  • 我建议使用弹簧配置文件 (org.springframework.context.support.PropertySourcesPlaceholderConfigurer) 来处理因环境而异的应用程序变量。这样,您可以构建一次并在下一个环境中重新部署它。不过,这可能与您的情况无关..

标签: maven war


【解决方案1】:

在 maven 中,您必须在 <module> 中使用 <bundleFileName>

您应该点击此链接以确保您的模块被重写: 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>

【讨论】:

    【解决方案2】:

    答案很简单……

    像这样在每个配置文件中定义一个属性...

    <profile>
        <id>qa</id>
        <properties>
            <rp.build.warname>ourapp-qa</rp.build.warname>
        </properties>
    </profile>
    

    然后将其添加到您的插件中...

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

    【讨论】:

    • 注意:此配置在 maven-war-plugin 3.0.0 中不再可用。
    【解决方案3】:

    你自己答对了:

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

    但有一种更简单的方法可以重新定义 WAR 名称:

    <build>
        <finalName>${rp.build.warname}-somearbitraryname</finalName>
        <!-- ... -->
    </build>
    

    不需要maven-war-plugin

    【讨论】:

    • 不错的提示,但与 Maven 文档一样,不应使用配置文件来产生不同的输出。否则,正如我所见,编译会变得不必要地复杂。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-22
    • 2013-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多