maven build packaging in different environments

1, pom.xml configure bulid plunge

2. Right-click run -> select maven build

 

What is wrong, what is changed, the project cannot be built as long as there is a red cross

 

 

Selection of different environment files:

Classic file replacement

General idea:

1. Different property files in different environments, key-value (the keys are the same)

 

2. Configure filter and profile in maven, and use different configuration files through different command parameters when packaging

 

3. Use the ${key} placeholder in other files to get different values ​​for different content in the properties file

 

 

 

pom.xml

 

 

 

         <profiles>

<profile>

<id>dev</id>

<properties>

<env-dir>META-INF/environments/dev</env-dir>

</properties>

<activation>

<activeByDefault>true</activeByDefault>

</activation>

</profile>

<profile>

<id>sit</id>

<properties>

<env-dir> META-INF / environments / sit </env-dir>

</properties>

</profile>

<profile>

<id>prod</id>

<properties>

<env-dir>META-INF/environments/prod</env-dir>

</properties>

</profile>

</profiles>

 

 

 

<build>

<finalName>${project.artifactId}</finalName>

 

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<configuration>

<source>1.7</source>

<target>1.7</target>

<encoding>UTF-8</encoding>

</configuration>

</plugin>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-resources-plugin</artifactId>

<configuration>

<encoding>UTF-8</encoding>

</configuration>

</plugin>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-war-plugin</artifactId>

<version>2.0.2</version>

<configuration>

</configuration>

</plugin>

</plugins>

<resources>

//The resource path specified under this node will be automatically placed in the class directory of the war package

<resource>

//The files under the path pointed to by ${env-dir} will be directed to src/main/resources/ and compiled according to this directory file

<directory>src/main/resources/${env-dir}</directory>

//The maven command after filtering is set here, and the package will automatically search for the profile node according to the input variable

<filtering>true</filtering>

</resource>

<resource>

<directory>src/main/resources</directory>

<includes>

<include>**/*.xml</include>

<include>**/*.properties</include>

</includes>

</resource>

</resources>

</build>

 

 

 

 

 

 

 

Order:

package -P development or (dev)

 

 

In this way, the resource naturally points to the corresponding directory META-INF/environments/dev

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

http://blog.csdn.net/tianmangshan80/article/details/51743923

 

http://blog.csdn.net/li295214001/article/details/52044800

 

http://www.cnblogs.com/cookiehu/p/4949629.html

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326154714&siteId=291194637