maven builds deployment packages for different environments

     After the project is completed and deployed, each environment has its own configuration parameters, such as database connection, ws address for remote calls, and so on. If you manually modify these parameters before building each environment, it is obviously too unreliable.

    However, it is not very suitable to write all these contents in pom.xml. It is better to split the properties file for storage, then the following configuration in pom can achieve the same effect.

  <profiles>
        <profile>
            <id>production</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>compile</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <tasks>
                                        <delete file="${project.build.outputDirectory}/reb-api.properties" />
                                        <copy file="src/main/resources/reb-api.production.properties" tofile="${project.build.outputDirectory}/reb-api.properties" />
                                    </tasks>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

 

 

When packaging, use mvn package -Pproduction

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326679984&siteId=291194637