不同环境打包不同文件的配置

1.同一目录下包含生产、测试、开发环境的文件,文件名采用模糊匹配,demo如下图:


pom.xml配置:

(1)

<!-- 打包环境参数配置 -->
	<profiles>
		   <profile>
        <!-- 本地开发环境 -->
        <id>dev</id>
        <properties>
            <environment>dev</environment>
        </properties>
	        <activation>
	            <activeByDefault>true</activeByDefault>
	        </activation>
	    </profile>
	    <profile>
	        <!-- 测试环境 -->
	        <id>test</id>
	        <properties>
	            <environment>test</environment>
	        </properties>
	    </profile>
	    <profile>
	        <!-- 生产环境 -->
	        <id>pro</id>
	        <properties>
	            <environment>pro</environment>
	        </properties>
	    </profile>
	</profiles>


<resources>
        <resource>
            <directory>src/main/resources</directory>
            <excludes>
                <exclude>configures/*</exclude>
            </excludes>
            <filtering>true</filtering>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>configures/${environment}*.properties</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
    <filters>
       <filter>src/main/resources/configures/config-${environment}.properties</filter>
    </filters>

excludes:需要过滤掉的文件

includes:打包引入的文件

2.生产、测试、开发环境在不同的目录需打包方式,例子如下图:


pom.xml配置:

(1)

	<!-- 打包环境参数配置 -->
	<profiles>
		<profile>
	        <!-- 本地开发环境 -->
	        <id>dev</id>
	        <properties>
	            <environment>dev</environment>
	        </properties>
		        <activation>
		            <activeByDefault>true</activeByDefault>
		        </activation>
		    </profile>
		    <profile>
		        <!-- 测试环境 -->
		        <id>test</id>
		        <properties>
		            <environment>test</environment>
		        </properties>
		    </profile>
		    <profile>
		        <!-- 生产环境 -->
		     	<id>pro</id>
		    <properties>
		       <environment>pro</environment>
		    </properties>
	    </profile>
	</profiles>
(2)
	<resources>
        <resource>
            <directory>src/main/resources</directory>
            <excludes>
                <exclude>configures/*/*</exclude>
            </excludes>
            <filtering>true</filtering>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>configures/${environment}/*.properties</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
总之照着第一个列子画的

猜你喜欢

转载自blog.csdn.net/jialanshun/article/details/80283026