1、不同配置檔案對應不同環境,例:dev對應測試壞境,properties對應開發壞境
2、修改配置檔案pom.xml 添加如下代碼: <profiles> <profile> <id>properties</id> <properties> <package.environment>properties</package.environment> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <id>dev</id> <properties> <package.environment>dev</package.environment> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> </profiles> 3、添加打包代碼:主要代碼為下劃線處 <build> <finalName>feidieshuo-workbench</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <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> </build> 4、打包指令: 用maven -v檢查maven是否安裝 cmd指定到對應pom.xml位置下執行下面語句 mvn clean install -Dmaven.檔案名.skip=true -P=檔案名