猿问

如何提取 Maven 配置文件中的公共部分

在我pom.xml的定义中,我定义了几个配置文件来在 Oracle WebLogic 下运行我的 Spring Boot 应用程序:


    <profile>

        <id>wls-1</id>

        <dependencies>

            <dependency>

                <groupId>org.springframework.boot</groupId>

                <artifactId>spring-boot-starter-tomcat</artifactId>

                <scope>provided</scope>

            </dependency>

        </dependencies>

        <properties>


        </properties>

    </profile>

    <profile>

        <id>wls-2</id>

        <dependencies>

            <dependency>

                <groupId>org.springframework.boot</groupId>

                <artifactId>spring-boot-starter-tomcat</artifactId>

                <scope>provided</scope>

            </dependency>

        </dependencies>

        <properties>


        </properties>

    </profile>

    <profile>

        <id>wls-3</id>

        <dependencies>

            <dependency>

                <groupId>org.springframework.boot</groupId>

                <artifactId>spring-boot-starter-tomcat</artifactId>

                <scope>provided</scope>

            </dependency>

        </dependencies>

        <properties>


        </properties>

    </profile>

    <profile>

        <id>tomcat1</id>

        <properties>


        </properties>

    </profile>

正如您在每个新wls配置文件中看到的那样,我需要定义依赖项以使用提供范围(否则部署将由于某些 tomcat 资源而失败)。但是我仍然有一些其他配置文件不会使用这wls-common部分


有没有办法我可以定义一些wls-common配置文件,这些配置文件将在不更改我的命令的情况下从那里自动使用mvn?我知道我可以在属性中mvn -P p1,p2或属性中链接个人资料,-Dp1=wls但这不是我想要的。


偶然的你
浏览 152回答 2
2回答

犯罪嫌疑人X

在您的所有配置文件中定义将激活特定配置文件并将它们全部放在通用配置文件中的属性。但是,这将要求您将命令从更改mvn -Pwls-1为mvn -Dwls-1<profile>&nbsp;<id>wls-1</id>&nbsp;<activation>&nbsp; &nbsp;<property>&nbsp; &nbsp; &nbsp;<name>wls-1</name>&nbsp; &nbsp;</property>&nbsp;</activation>&nbsp;...</profile>&nbsp;<profile>&nbsp; &nbsp; <id>common</id>&nbsp; &nbsp; <activation>&nbsp; &nbsp; &nbsp; <property>&nbsp; &nbsp; &nbsp; &nbsp; <name>wls-1</name>&nbsp; &nbsp; &nbsp; &nbsp; <name>wls-2</name>&nbsp; &nbsp; &nbsp; &nbsp; <name>wls-3</name>&nbsp; &nbsp; &nbsp; </property>&nbsp; &nbsp; </activation>&nbsp; &nbsp; <dependencies>&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-tomcat</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <scope>provided</scope>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; </dependencies>&nbsp; &nbsp; <properties>&nbsp; &nbsp; </properties></profile>

12345678_0001

您不能从另一个配置文件激活配置文件。您只能通过命令行、标记文件、操作系统等外部方式激活它们。
随时随地看视频慕课网APP

相关分类

Java
我要回答