【问题标题】:Maven - Calling a module from Parent POM based on the profileMaven - 根据配置文件从父 POM 调用模块
【发布时间】:2011-02-17 10:50:07
【问题描述】:

我有一个模块应该产生两个工件(战争)。两个 WAR 之间的唯一区别是使用的 web.xml。
我在 Maven Profiles 的帮助下做到了这一点......

<parent>
    <artifactId>com</artifactId>
    <groupId>myProj</groupId>
    <version>1.0</version>
</parent>

<groupId>myProj.module1</groupId>
<artifactId>module1</artifactId>
<version>1.0</version>
<packaging>war</packaging>

<profiles>

    <profile>
        <id>module1</id>
        <build>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <warName>module1</warName>
                    <webXml>src\main\webapp\WEB-INF\web_module1.xml</webXml>
                </configuration>
            </plugin>
            </plugins>
        </build>
    </profile>


    <profile>
        <id>module2</id>
        <build>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <warName>module2</warName>
                    <webXml>src\main\webapp\WEB-INF\web_module2.xml</webXml>
                </configuration>
            </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

Q1:如何从超级 POM 调用此 POM,以便激活两个配置文件?
Q2:是否可以在本地存储库中安装两个生成的工件?

谢谢!

【问题讨论】:

    标签: maven pom.xml profiles


    【解决方案1】:

    当你想activate several profiles at the same time时,你只需要运行mvn ... -Pprofile1,profile2命令。

    但是,在您的情况下,这违反了一个主要的 Maven 约定,该约定指出 one project = one artifact。这意味着您不能同时创建 2 个 WAR。如果您激活这两个配置文件,maven-war-plugin 的一个配置将被第二个配置文件覆盖,然后,您最终将获得 1 个 WAR,一个 web.xml。

    如果您想获得 2 个 WAR,解决方案是使用 WAR overlay(即第二个战争是另一个依赖战争 #1 的项目),或者运行两个单独的 Maven 命令,每个配置文件一个。

    【讨论】:

    • 谢谢 romaintaz。有什么方法可以让我在个人资料的帮助下给我的孩子打电话……可以这样做:&lt;module&gt;....&lt;/module&gt;
    • 好吧,我使用了“叠加层”。这两个工件使用相同的代码库,但不同的“web.xml”
    猜你喜欢
    • 2010-12-31
    • 1970-01-01
    • 2013-02-23
    • 1970-01-01
    • 2019-07-24
    • 2020-04-26
    • 1970-01-01
    • 2016-06-27
    • 1970-01-01
    相关资源
    最近更新 更多