maven根据不同环境打不同的war
程序员文章站
2022-06-21 21:12:57
...
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gpcsoft.hct.etp</groupId>
<artifactId>gjp</artifactId>
<packaging>war</packaging>
<version>1.0.0</version>
<name>专区</name>
<url>https://z.test.com.cn/</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<springframework.version>3.0.0.M3</springframework.version>
<java.home>C:\\gjp_soft\\soft\\jdk_645\\jdk6\\jdk1.6.0_45</java.home>
</properties>
<repositories>
<repository>
<id>public</id>
<name>Public Repositories</name>
<url>http://111.90.242.211:8081/nexus/content/groups/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public</id>
<name>Public Repositories</name>
<url>http://111.90.242.211:8081/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>com.gpcsoft.srplatform</groupId>
<artifactId>srplatform-core</artifactId>
<version>0.6.0</version>
<exclusions>
<exclusion>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<!-- maven多环境设置 add by andrew20180621 -->
<profiles>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>prod</id>
<properties>
<env>prod</env>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<env>test</env>
</properties>
</profile>
<profile>
<id>show</id>
<properties>
<env>show</env>
</properties>
</profile>
<profile>
<id>closetoprod</id>
<properties>
<env>closetoprod</env>
</properties>
</profile>
</profiles>
<build>
<finalName>cgjy</finalName>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.class</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF8</encoding>
<compilerArguments>
<verbose />
<!-- windows格式的 -->
<bootclasspath>${java.home}/jre/lib/rt.jar;${java.home}/jre/lib/jce.jar;${java.home}/jre/lib/jsse.jar</bootclasspath>
<!-- linux格式的 -->
<!-- <bootclasspath>${java.home}/jre/lib/rt.jar:${java.home}/jre/lib/jce.jar:${java.home}/jre/lib/jsse.jar</bootclasspath> -->
</compilerArguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
</plugin>
<!-- 释放将项目的类文件打成jar放到lib目录中。 打成jar的好处是:只修改class时,可以只更新jar。 -->
<!-- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archiveClasses>true</archiveClasses>
<webResources>
<resource>
copy src/main/resource/** to WEB-INF/classes.
<directory>src/main/resources</directory>
<targetPath>WEB-INF/classes</targetPath>
<filtering>false</filtering>
</resource>
</webResources>
</configuration>
</plugin> -->
<!-- maven打包插件 add by andrew -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<!-- maven打包的时候告诉maven不需要web.xml,否刚会报找不到web.xml错误 -->
<failOnMissingWebXml>false</failOnMissingWebXml>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>src/main/resources/profiles/${env}/</directory>
<targetPath>WEB-INF/classes</targetPath>
<filtering>true</filtering>
</resource>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>src/main/resources/</directory>
<targetPath>WEB-INF/classes</targetPath>
<filtering>true</filtering>
</resource>
</webResources>
<!-- 排除不需要的文件夹 -->
<packagingExcludes>file/**</packagingExcludes>
</configuration>
</plugin>
<plugin>
<!-- 跳过单元测试 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<url>http://localhost:8088/manager</url>
<server>tomcat6-manager</server>
<username>tomcat</username>
<password>tomcat</password>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
推荐阅读