根据pom中的活动配置文件更改包装

mat*_*asg 35 java maven-2

我有一个用maven编译的项目.我在pom.xml中声明了不同的配置文件.对于其中一些配置文件,我更喜欢建立一个战争,而对于其他配置文件,我更喜欢一个jar.我用来手动编辑pom.xml文件并将包装变量更改为

<packaging>war</packaging>
Run Code Online (Sandbox Code Playgroud)

要么

<packaging>jar</packaging>
Run Code Online (Sandbox Code Playgroud)

在做之前

$ mvn clean package -Pchosenprofile
Run Code Online (Sandbox Code Playgroud)

如何告诉mvn每个配置文件对应的包装,这样我就不需要编辑pom.xml了?

Tor*_*res 105

如果您想使用个人资料,您可以使用以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <modelVersion>4.0.0</modelVersion>
    ..
    <packaging>${packaging.type}</packaging>

    <profiles>
        <profile>
            <id>webapp</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <packaging.type>war</packaging.type>
            </properties>
        </profile>
        <profile>
            <id>batch</id>
            <properties>
                <packaging.type>jar</packaging.type>
            </properties>
                </profile>
          </profiles>
</project>
Run Code Online (Sandbox Code Playgroud)

  • 这太容易了,让我微笑.谢谢,即使它来晚了一年:). (12认同)