Maven 打包不同环境

支持不同环境打包

1 pom添加如下配置:

1)添加指定打包id 区分各个环境

         <profiles>

                   <profile>

                   <id>dev</id>

                   <properties>

                   <package.environment>dev</package.environment>

                   </properties>

                   </profile>

                   <profile>

                   <id>sit1</id>

                   <properties>

                   <package.environment>sit1</package.environment>

                   </properties>

                   </profile>

                   <profile>

                   <id>sit2</id>

                   <properties>

                   <package.environment>sit2</package.environment>

                   </properties>

                   </profile>

                   <profile>

                   <id>sit3</id>

                   <properties>

                   <package.environment>sit3</package.environment>

                   </properties>

                   </profile>

                   <profile>

                   <id>uat</id>

                   <properties>

                   <package.environment>uat</package.environment>

                   </properties>

                   </profile>

         </profiles>

2)添加打包资源文件

         <build>

                   <finalName>qbweb</finalName>

                   <plugins>

                   <plugin>

                   <artifactId>maven-compiler-plugin</artifactId>

                   <configuration>

                   <source>1.7</source>

                   <target>1.7</target>

                   <compilerArguments>

                   <verbose />

                   <bootclasspath>${java.home}\lib\rt.jar;${java.home}\lib\jce.jar</bootclasspath>

                   </compilerArguments>

                   </configuration>

                   </plugin>

                   <!--指定不过滤的文件,否则会乱码-->

                   <!-- 过滤后缀为pem、pfx的证书文件 -->

                   <plugin>

                   <groupId>org.apache.maven.plugins</groupId>

                   <artifactId>maven-resources-plugin</artifactId>

                   <configuration>

                   <encoding>UTF-8</encoding>

                   <nonFilteredFileExtensions>

                   <nonFilteredFileExtension>der</nonFilteredFileExtension>

                   <nonFilteredFileExtension>dat</nonFilteredFileExtension>

                   <nonFilteredFileExtension>xls</nonFilteredFileExtension>

                   <nonFilteredFileExtension>xlsx</nonFilteredFileExtension>

                   </nonFilteredFileExtensions>

                   </configuration>

                   </plugin>

                   </plugins>

                   <resources>

                   <resource>

                   <directory>src/main/java</directory>

                   <includes>

                   <include>**/*.xml</include>

                   </includes>

                   <excludes>

                   <exclude>**/*.java</exclude>

                   <exclude>**/.svn/*</exclude>

                   </excludes>

                   </resource>

                   <resource>

                   <directory>src/main/resources</directory>

                   <filtering>true</filtering>

                   <!--包含那个文件夹下,那个后缀的文件-->

                   <includes>

                   <include>attachment/**</include>

                   <include>**/*.properties</include>

                   <include>**/*.xml</include>

                   <include>**/*.conf</include>

                   </includes>

                   <!--排除那个文件夹下,那个后缀的文件-->

                   <excludes>

                   <exclude>config/**</exclude>

                   <exclude>remark/**</exclude>

                   <exclude>genCodeTemplate/**</exclude>

                   </excludes>

                   </resource>

                   <resource>

                   <!--${package.environment} 步骤1 声明的内容-->

                   <directory>src/main/resources/config/${package.environment}</directory>

                   <!--用指定的值替换占位符的内容 最后会以 config下面的文件为准-->

                   <filtering>true</filtering>

                   <includes>

                   <include>auth-client.xml</include>

                   <include>CAS_SSO.properties</include>

                   <include>jdbc.properties</include>

                   <include>logback.xml</include>

                   <include>spring-dubbo-consumer.xml</include>

                   <include>rabbitmq.properties</include>

                   </includes>

                   </resource>

                   </resources>

         </build>

2 打包war 包

run as .. 输入 package -P dev(sit1)这里的内容是指步骤1 声明的id的内容

如 package -P sit1 -Dskip Tests 打包集成一环境并跳过测试用例代码

注意:不需要特殊的安装插件

posted @ 2018-02-28 17:19  暖暖-木木  阅读(427)  评论(0编辑  收藏  举报