maven动态打包配置文件

梦里梦外; 2022-02-28 10:44 324阅读 0赞

主要通过配置pom来实现!!

1、resources下加入各环境的配置

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3p6Y2hhbmNlcw_size_16_color_FFFFFF_t_70

2、pom文件中加入以下几部分

  1. <profiles>
  2. <profile>
  3. <id>dev</id>
  4. <properties>
  5. <profileActive>enviroment/dev</profileActive>
  6. </properties>
  7. <activation>
  8. <activeByDefault>true</activeByDefault>
  9. </activation>
  10. </profile>
  11. <profile>
  12. <id>test</id>
  13. <properties>
  14. <profileActive>enviroment/test</profileActive>
  15. </properties>
  16. </profile>
  17. </profiles>
  18. <build>
  19. <resources>
  20. <resource>
  21. <directory>src/main/resources</directory>
  22. <excludes>
  23. <exclude>*/dev/*.properties</exclude>
  24. <exclude>*/test/*.properties</exclude>
  25. </excludes>
  26. <filtering>true</filtering>
  27. </resource>
  28. </resources>
  29. <pluginManagement>
  30. <plugins>
  31. <plugin>
  32. <artifactId>maven-war-plugin</artifactId>
  33. <version>3.2.2</version>
  34. <configuration>
  35. <webResources>
  36. <resource>
  37. <directory>src/main/resources/${profileActive}</directory>
  38. <targetPath>WEB-INF/classes</targetPath>
  39. <filtering>true</filtering>
  40. </resource>
  41. </webResources>
  42. </configuration>
  43. </plugin>
  44. </plugins>
  45. </pluginManagement>

3、在打包的时候我们添加上-P参数,-P后跟对应环境,即可打包对应的配置文件啦

916267-20161201124958427-1851560425.png

发表评论

表情:
评论列表 (有 0 条评论,324人围观)

还没有评论,来说两句吧...

相关阅读