maven分环境 打包

resources包下properties包中jdbc.properties
jdbc_driverClassName=${jdbc.driverClassName}//pom中jdbc.driverClassName变量
jdbc_url=${jdbc.url}
jdbc_username=${jdbc.username}
jdbc_password=${jdbc.password}
pom.xml
<profiles>
<profile>
<id>dev</id>
<properties>
<jdbc.driverClassName>com.mysql.jdbc.Driver</jdbc.driverClassName>
<jdbc.url>jdbc:mysql://xx.xx.xx.xx:3306/rhkj?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&&allowMultiQueries=true</jdbc.url>
<jdbc.username>root</jdbc.username>
<jdbc.password>123456</jdbc.password>
</properties>
//默认打包dev环境
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<jdbc.driverClassName>com.mysql.jdbc.Driver</jdbc.driverClassName>
<jdbc.url>jdbc:mysql://xx.xx.xx.xx:3306/rhkj?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&&allowMultiQueries=true</jdbc.url>
<jdbc.username>root</jdbc.username>
<jdbc.password>123456</jdbc.password>
</properties>
</profile>
</profiles>
<build>
//要copy的文件
<resources>
<resource>
//resources文件夹下除了properties文件夹中文件
<directory>${project.basedir}/src/main/resources</directory>
//是否用pom中变量属性值替换 copy的文件中的变量的属性值
<filtering>false</filtering>
//copy排除properties文件夹中文件
<excludes>
<exclude>properties/*</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
//default生命周期中compile阶段
<phase>compile</phase>
<goals>
//compile阶段中 copy-resources方法
<goal>copy-resources</goal>
</goals>
<configuration>
<overwrite>true</overwrite>
//copy的目标目录 project.build.outputDirectory:内置变量 class文件夹路径
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<resources>
//额外 要copy properties属性文件夹并将内部变量替换
<resource>
<directory>src/main/resources/properties</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
选择dev环境 打包命令 mvn package -P dev

6007

被折叠的 条评论
为什么被折叠?



