<profiles>
<profile>
<id>dev</id>
<properties>
<package.target>dev</package.target>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>prod</id>
<properties>
<package.target>prod</package.target>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<package.target>test</package.target>
</properties>
</profile>
</profiles>
<build>
<finalName>${artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
</plugin>
<!--构建配置文件环境-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>add-resource</id>
<phase>generate-resources</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/main/resources/props-${package.target}</directory>
<targetPath>props</targetPath>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
filter
serverConfig.properties
jdbc.url=${jdbc.url}
jdbc.username=${jdbc.username}
jdbc.password=${jdbc.password}
jdbc.maxActive=${jdbc.maxActive}
serverConfig-dev.properites
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://172.26.32.9:3308/chat_cms?useUnicode=true&characterEncoding=utf8
jdbc.username=develop
<filters>
<filter>src/main/resources/serverConfig-${env}.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>serverConfig.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>