1

我有一个模块应该产生两个工件(战争)。两个 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:是否可以在本地存储库中安装两个生成的工件?

谢谢!

4

1 回答 1

2

当您想同时激活多个配置文件时,您只需运行mvn ... -Pprofile1,profile2命令。

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

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

于 2011-02-17T10:56:20.843 回答