maven plug-ins load different environment configuration files according to configuration and package them (maven war plugin)

1. Configure a variety of different environments

Such as (local local, dev development, test environment, etc.)

 1   <profiles>
 2         <profile>
 3             <id>local</id>
 4             <properties>
 5                 <package.environment>local</package.environment>
 6             </properties>
 7         </profile>
 8         
 9         <profile>
10             <id>dev</id>
11             <properties>
12                 <package.environment>dev</package.environment>
13             </properties>
14             <!-- Specify which configuration to use -->
15             <activation>
16                 <activeByDefault>true</activeByDefault>
17             </activation>
18         </profile>
19 
20         <profile>
21             <id>test</id>
22             <properties>
23                 <package.environment>test</package.environment>
24             </properties>
25         </profile>
26     </profiles>

Line 15-17 specifies to use this environment configuration, which can be placed in different < profile >. You need to create corresponding configuration folders in the project directory, such as local, dev, test, etc., as follows

common folder is the general configuration of the project, dev is the configuration of the development environment, and test is the configuration of the test environment

2. Configure the following under build

 1 <build>
 2         <finalName>demo entry name</finalName>
 3         <resources>
 4             <resource>  
 5                 <directory>src/main/java</directory>  
 6                 <includes>  
 7                     <include>**/*.xml</include>  
 8                 </includes>  
 9                 <filtering>false</filtering>  
10             </resource>  
11             <resource>
12                 <directory>src/main/resources</directory>
13                 <filtering>true</filtering>
14                 <excludes>
15                     <exclude>local/*</exclude>
16                     <exclude>test/*</exclude>
17                     <exclude>dev/*</exclude>
18                     <exclude>common/*</exclude>
19                 </excludes>
20             </resource>
21         </resources>
22         <plugins>
23             <plugin>
24                 <groupId>org.apache.maven.plugins</groupId>
25                 <artifactId>maven-war-plugin</artifactId>
26                 <version>2.3</version>
27                 <configuration>
28                     <encoding>UTF-8</encoding>  
29                     <archive>
30                         <addMavenDescriptor>false</addMavenDescriptor>
31                     </archive>
32                     <warName>NACPortal_${package.environment}</warName>
33                     <webResources>
34                         <resource>
35                             <directory>src/main/resources/${package.environment}</directory>
36                             <targetPath>WEB-INF/classes</targetPath>
37                             <filtering>true</filtering>
38                         </resource>
39                         <resource>
40                             <directory>src/main/resources/common</directory>
41                             <targetPath>WEB-INF/classes</targetPath>
42                             <filtering>true</filtering>
43                         </resource>
44                     </webResources>
45                 </configuration>
46             </plugin>
47             <!-- Compile configuration is configured according to different versions-->
48             <plugin>
49               <artifactId>maven-compiler-plugin</artifactId>
50               <configuration>
51                   <source>1.8</source>
52                   <target>1.8</target>
53                   <encoding>UTF-8</encoding>
54                   <compilerArguments>
55                    <extdirs>src\main\webapp\WEB-INF\lib</extdirs>
56                   </compilerArguments>
57               </configuration>
58             </plugin>
59         </plugins>
60 </build>

During the development process, you can configure

<activation>
    <activeByDefault>true</activeByDefault>
</activation>

Package in different environment in corresponding configuration environment.

After mvn install is executed, corresponding war packages can be generated, such as project? Dev.war, project? Test.war, etc

So far, it's done!!

 

 

 

profile  ['prəʊfaɪl]  detailedX
Basic translation
n. profile; profile; profile; profile
vt. drawing... The outline of; a brief description
vi. outline
Network definition
Profile: outline
Bevel Profile: bevel profile
tooth profile: tooth profile

Tags: Java encoding Maven xml

Posted on Tue, 03 Dec 2019 18:01:07 -0800 by ialsoagree