我想爲不同的maven配置文件提供不同的spring配置文件。 Filtering接近我想要的,但它只更改一個文件內的屬性。我想要的是包括/排除和根據配置文件重命名文件。例如,我有文件profile1-config.xml和profile2-config.xml。對於profile1,構建profile1-config.xml被重命名爲config.xml,profile2-config.xml被排除在構建之外。對於profile2構建,profile2-config.xml被重命名爲config.xml,profile1-config.xml被排除在構建之外。 這可能在maven中嗎?maven包含不同配置文件的不同文件
2
A
回答
0
你的想法不是這樣的,但是如果你修改它,它會做如下:
說你願意爲每個配置文件創建的conf文件夾和吮吸它的那些文件。
src/main/conf
|-/profile1/conf.xml
|-/profile2/conf.xml
等等。配置您的配置文件接收這些文件。如果您打算爲某個服務器部署不同的配置,則最好使用其他模塊和戰爭覆蓋,因爲您無法一次在Nexus或本地存儲庫中部署同一模塊項目的多個配置。更重要的是,考慮到許多配置文件會混淆你的pom,並給構建帶來更多複雜性。
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>
相關問題
- 1. Maven:不同配置文件的不同屬性文件
- 2. ipa文件不包含配置文件
- 3. 如何根據構建配置包含不同的JavaScript文件?
- 4. 每個構建配置包含不同的文件
- 5. 不同環境的Maven配置文件 - 不好的做法?
- 6. 不能使用不同的配置文件構建maven項目
- 7. 包含與primefaces不同的文件
- 8. 包含文件在不同的目錄
- 9. 發佈網頁:包含不同文件取決於配置文件
- 10. Maven - 爲不同的版本使用不同的設置文件
- 11. Maven:包含基於配置文件的資源文件
- 12. 不同頭文件包含路徑
- 13. 不同版本的相同配置文件在不同分支
- 14. maven中不同構建配置文件的不同依賴關係
- 15. Eclipse和Maven中的Log4j2 - 需要不同的配置文件
- 16. 在不同的依賴關係的Maven配置文件
- 17. 在maven中配置不同文件類型的編碼?
- 18. Dev和prod使用Maven的不同配置文件
- 19. Maven,切換到不同的配置文件
- 20. Web.config文件和不同的配置missmatch
- 21. 可以在不同的文件中定義Maven配置文件嗎?
- 22. php文件包含不同目錄下的文件
- 23. Gradle同步失敗:預期配置':backend:appengineSdk'只包含一個文件,但不包含文件
- 24. jar文件不同於不同的maven(相同版本)?
- 25. Zip文件包含相同的文件,但具有不同的哈希值?
- 26. Homestead ip不同於配置文件
- 27. 針對不同服務器的不同配置文件
- 28. 複製包含在不同父文件夾中的許多文件(同名)
- 29. 在PHP中包含來自不同文件的同名數組?
- 30. 如何包含同一頭文件的兩個不同版本?