在我的 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
但这不是我要找的。p>
最佳答案
在您的所有配置文件中定义将激活特定配置文件的属性并将所有这些配置文件放在通用配置文件中。
然而,这将需要您将命令从 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/