maven分环境 打包

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&amp;characterEncoding=utf8&amp;rewriteBatchedStatements=true&amp;&amp;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&amp;characterEncoding=utf8&amp;rewriteBatchedStatements=true&amp;&amp;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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值