maven打包多环境配置

1、pom.xml

    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <env>dev</env>
            </properties>
        </profile>
        <profile>
            <id>prd</id>
            <properties>
                <env>prd</env>
            </properties>
        </profile>
    </profiles>

    <build>
         <resources>
            <resource>
                <directory>src/main/resources</directory>
                <excludes>
                    <exclude>dev/*</exclude>
                    <exclude>prd/*</exclude>
                </excludes>
            </resource>
            <resource>
                <directory>src/main/resources/${env}</directory>
            </resource>
        </resources>
	</build>

2、配置文件目录如下图:

3、mvn命令打包

 

注意:项目中使用了mybatis-generator插件,在使用mvn package命令打包时,mybatis-generator也会执行,导致在dao中自定义的函数被删除。

原因:是因为mybatis-generator插件默认绑定了package的生命周期

解决:在pom中手动设置一下mybatis-generator插件绑定的生命周期即可

<executions>
	<execution>
		<id>Generate MyBatis Artifacts</id>
		<phase>deploy</phase>
		<goals>
			<goal>generate</goal>
		</goals>
	</execution>
</executions>
发布了45 篇原创文章 · 获赞 5 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/L15810356216/article/details/96339467