pom.xml配置
<profiles> <profile> <id>dev</id> <properties> <token>dev</token> </properties> <!-- 默认打包参数 --> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <id>test</id> <properties> <token>test</token> </properties> </profile> </profiles> <build>
<!-- 开启资源配置--> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> </build>
test.properties
token=${token}
*.java // 获取参数的java类
public class TokenTestPom { private static ResourceBundle resource = ResourceBundle.getBundle("token"); public static final String TOKEN= resource.getString("token"); }
项目打包命令:
mvn install -Ptest