人工智能,零基础入门!http://www.captainbed.net/inner  

针对多环节,从源头打包入手,当然这些都可以在运维阶段用脚本进行替换来代替

resources/environment/下有四个环境,local本地、dev开发、test测试、pre预上线、prod生产,打包命令如下:

# 本地
mvn clean package -P local
# 开发
mvn clean package -P dev
# 测试
mvn clean package -P test
# 预上线
mvn clean package -P pre
# 生产
mvn clean package -p prod

说明:每个环境的文件夹下的配置文件可以全量放,也可以试增量,最终会覆盖

项目目录如下所示:

部分POM如下说是:

<profiles>
    <!-- 本地环境 -->
    <profile>
        <id>local</id>
        <properties>
            <package.environment>local</package.environment>
        </properties>
        <!-- 是否默认 -->
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    <!-- 开发环境 -->
    <profile>
        <id>dev</id>
        <properties>
            <package.environment>dev</package.environment>
        </properties>
    </profile>
    <profile>
        <!-- 测试环境 -->
        <id>test</id>
        <properties>
            <package.environment>test</package.environment>
        </properties>
    </profile>
    <profile>
        <!-- 预上线 -->
        <id>pre</id>
        <properties>
            <package.environment>pre</package.environment>
        </properties>
    </profile>
    <profile>
        <!-- 生产环境 -->
        <id>prod</id>
        <properties>
            <package.environment>prod</package.environment>
        </properties>
    </profile>
</profiles>

<build>
    <finalName>ssm-framework</finalName>
    <plugins>
        <!-- war包打包组件 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>${maven-war-plugin.version}</version>
            <configuration>
                <webResources>
                    <resource>
                        <!-- 元配置文件的目录,相对于pom.xml文件的路径 -->
                        <directory>src/main/webapp/WEB-INF</directory>
                        <!-- 是否过滤文件,也就是是否启动auto-config的功能 -->
                        <filtering>true</filtering>
                        <!-- 目标路径 -->
                        <targetPath>WEB-INF</targetPath>
                    </resource>
                    <resource>
                        <directory>src/main/resources/environment/${package.environment}</directory>
                        <targetPath>WEB-INF/classes</targetPath>
                        <filtering>true</filtering>
                    </resource>
                </webResources>
            </configuration>
        </plugin>
	</plugins>
</build>

 

 

 

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐