maven profile实现多环境打包

来源:互联网 发布:淘宝拍卖车辆靠谱吗 编辑:程序博客网 时间:2024/05/01 05:31

项目开发需要有多个环境,一般为开发,测试,预发,正式4个环境,通过maven可以实现按不同环境进行打包部署,命令为: 

mvn package -P dev

其中“dev“为环境的变量id, 可以自己定义, 我定义的名称为:dev,sit,uat,prod , 具体在pom.xml中的配置如下:

<properties><package.environment>sit</package.environment></properties><profiles><profile><id>dev</id><properties><package.environment>dev</package.environment></properties></profile><profile><id>sit</id><properties><package.environment>sit</package.environment></properties></profile><profile><id>uat</id><properties><package.environment>uat</package.environment></properties></profile><profile><id>prod</id><properties><package.environment>prod</package.environment></properties></profile></profiles>    <build>    <finalName>mytest</finalName>    <plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><encoding>UTF-8</encoding><source>1.8</source><target>1.8</target>  <!-- 指定编译级别,默认1.5 --></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><version>2.1.1</version><configuration><archive><addMavenDescriptor>false</addMavenDescriptor></archive><webResources><resource>this is relative to the pom.xml directory<directory>src/main/resources/${package.environment}</directory><targetPath>WEB-INF/classes</targetPath><filtering>true</filtering></resource></webResources></configuration></plugin></plugins><resources><resource><directory>src/main/java</directory><includes><include>**/*.xml</include></includes></resource><resource><directory>src/main/resources</directory><includes><include>**/*.*</include></includes><excludes><exclude>sql/oracle/*.*</exclude><exclude>sql/mysql/init/*.*</exclude><exclude>sit/**/*.*</exclude><exclude>uat/**/*.*</exclude><exclude>prod/**/*.*</exclude></excludes></resource></resources>  </build>


0 0
原创粉丝点击