一、项目目录结构
二、pom文件中引入maven-resources-plugin插件和相关的标签
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.5</version> <executions> <execution> <id>copy-resources</id> <phase>compile</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <overwrite>true</overwrite> <outputDirectory>${project.build.outputDirectory}</outputDirectory> <resources> <resource> <directory>src/main/resources/${active.profile}</directory> <filtering>false</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin> </plugins> <resources> <resource> <directory>src/main/resources</directory> <excludes> <exclude>dev/*</exclude> <exclude>prod/*</exclude> </excludes> <!--<filtering>true</filtering>--> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.xml</include> </includes> </resource> </resources> </build>
<profiles> <profile> <id>dev</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <active.profile>dev</active.profile> </properties> </profile> <profile> <id>prod</id> <properties> <active.profile>prod</active.profile> </properties> </profile> </profiles>
打包命令:
mvn clean install -Pdev
mvn clean install -Pprod