我想为不同的maven配置文件提供不同的弹簧配置文件。 Filtering接近我想要的,但它只更改一个文件中的属性。我想要的是包括/排除和重命名文件取决于配置文件。例如,我有文件profile1-config.xml和profile2-config.xml。对于profile1 build,profile1-config.xml重命名为config.xml,profile2-config.xml从构建中排除。对于profile2 build,profile2-config.xml重命名为config.xml,profile1-config.xml从构建中排除。 这可能在maven中吗?
答案 0 :(得分:0)
你的想法不会那样,但如果你修改它,它将按如下方式进行:
假设您为每个配置文件创建conf文件夹并将其吸收。
src/main/conf
|-/profile1/conf.xml
|-/profile2/conf.xml
等等。配置您的个人资料接收这些文件。如果您打算为某个服务器部署不同的配置,最好使用其他模块和战争覆盖,因为您无法在Nexus或本地存储库中同时部署同一模块项目的多个配置。更重要的是,请考虑许多配置文件会使您的pom混乱,并为构建带来更多复杂性。
答案 1 :(得分:0)
一般的想法是在maven-resources-plugin中使用copy-resources目标。
您可以创建一个文件夹来保存所有个人资料,例如:
profiles
|-profile1
|-profile2
在你的pom.xml中,你可以拥有这些设置:
<profiles>
<profile>
<id>profile1</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes</outputDirectory>
<resources>
<resource>
<directory>${basedir}/profiles/profile1</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>profile2</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes</outputDirectory>
<resources>
<resource>
<directory>${basedir}/profiles/profile2</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>