<!--多环境配置--> <profiles> <profile> <id>dev</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <!--数据库连接信息--> <jdbc.type>oracle</jdbc.type> <jdbc.driver>oracle.jdbc.driver.OracleDriver</jdbc.driver> <jdbc.url>jdbc:oracle:thin:@***</jdbc.url> <jdbc.username>***</jdbc.username> <jdbc.password>root</jdbc.password> <jdbc.pool.init>20</jdbc.pool.init> <jdbc.pool.minIdle>10</jdbc.pool.minIdle> <jdbc.pool.maxActive>100</jdbc.pool.maxActive> <!--是否开启用户的权限--> <user.Permissions>false</user.Permissions> </properties> </profile> <profile> <id>pro</id> <activation> <activeByDefault>false</activeByDefault> </activation> <properties> <!--数据库连接信息--> <jdbc.type>oracle</jdbc.type> <jdbc.driver>oracle.jdbc.driver.OracleDriver</jdbc.driver> <jdbc.url>jdbc:oracle:thin:***</jdbc.url> <jdbc.username>***</jdbc.username> <jdbc.password>***</jdbc.password> <jdbc.pool.init>20</jdbc.pool.init> <jdbc.pool.minIdle>10</jdbc.pool.minIdle> <jdbc.pool.maxActive>500</jdbc.pool.maxActive> <!--是否开启用户的权限--> <user.Permissions>true</user.Permissions> </properties> </profile> </profiles>
1.上述pom文件内容片断就是多环境配置的maven环境变量,默认只能在pom中使用。
2.这个属性设置为true,表示默认启用的环境。
<activation> <activeByDefault>false</activeByDefault> </activation>
3.pom文件中的环境变量,也可以用到项目中,需要用 build resources,如下述pom文件内容片断。
<!--编译配置--> <build> <outputDirectory>${project.basedir}/src/main/webapp/WEB-INF/classes/</outputDirectory> <plugins> <!-- Compiler 插件, 设定JDK版本 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <source>1.7</source> <target>1.7</target> <showWarnings>true</showWarnings> <compilerArguments> <verbose/> <bootclasspath>${java.home}/lib/rt.jar;${java.home}/lib/jce.jar</bootclasspath> </compilerArguments> </configuration> </plugin> <!-- resource插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.7</version> </plugin> <!-- install插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-install-plugin</artifactId> <version>2.5.2</version> </plugin> <!-- clean插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-clean-plugin</artifactId> <version>2.6.1</version> </plugin> <!-- dependency插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.10</version> </plugin> </plugins> <resources> <resource> <directory>${project.basedir}/src/main/resources</directory> <filtering>true</filtering> </resource> </resources> </build>