java - 如何提取 Maven 配置文件中的公共(public)部分

标签 java maven spring-boot

在我的 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配置文件将自动从那里使用配置文件 WITHOUT 更改我的 mvn命令?我知道我可以在 mvn -P p1,p2 中链接配置文件或属性(property) -Dp1=wls但这不是我要找的。

最佳答案

在您的所有配置文件中定义将激活特定配置文件的属性并将所有这些配置文件放在通用配置文件中。

然而,这将需要您将命令从 mvn -Pwls-1 更改为 mvn -Dwls-1

<profile>
 <id>wls-1</id>
 <activation>
   <property>
     <name>wls-1</name>
   </property>
 </activation>
 ...
</profile> 
<profile>
    <id>common</id>
    <activation>
      <property>
        <name>wls-1</name>
        <name>wls-2</name>
        <name>wls-3</name>
      </property>
    </activation>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <properties>
    </properties>
</profile>

关于java - 如何提取 Maven 配置文件中的公共(public)部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54346016/

相关文章:

java - 如何获取不同Annotation的值

java - 从另一个类调用参数化方法

java - org.springframework.web.servlet.PageNotFound noHandlerFound 未找到带有 URI 的 HTTP 请求的映射。我已将项目部署为 Maven 项目

java - 如何在 Weblogic 12c 上部署 Spring Boot(非 Web)应用程序

关于 HTMLEditorKit 的 Java 编程

java - 为 Fitnesse 输出方法提供参数?

java - 如何创建一个具有依赖关系的 jar 作为主要构建 Artifact ,稍后由程序集插件使用?

java - Web应用程序java从文件加载资源

java - 只读数据的 Spring Boot 存储库 : @Query annotation type not applicable to this kind of declaration

java - 自动转换为多个域对象的集中式 bean