首页 > 代码库 > maven项目配置框架

maven项目配置框架

任何一个maven项目都会继承一个默认的父pom配置:Super POM,详见:https://maven.apache.org/guides/introduction/introduction-to-the-pom.html 。
在pom.xml中可以直接使用一些变量值,如:

${project.groupId}               The group id of current project
${project.version}          The version of current project
${project.build.sourceDirectory} The source directory of current project
${project.basedir}               The directory that the current project resides in.
${project.baseUri}               The directory that the current project resides in, represented as an URI. Since Maven 2.1.0
${maven.build.timestamp}         The timestamp that denotes the start of the build. Since Maven 2.1.0-M1

详见:https://maven.apache.org/guides/introduction/introduction-to-the-pom.html之Available Variables

 

一个实际完整的生产项目maven配置框架示例:

技术分享
 1 <?xml version="1.0"?>
 2 <project
 3     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
 4     xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 5     <modelVersion>4.0.0</modelVersion>
 6     
 7     <artifactId>xxx-xxx</artifactId>
 8     <version>x.x.x</version>
 9     <packaging>war</packaging>
10     <name>xxx</name>
11     <url>xxx</url>
12     
13     <!-- 父模块,可选. -->
14     <parent>
15         <groupId>xxx</groupId>
16         <artifactId>xxx</artifactId>
17         <version>x.x.x</version>
18     </parent>
19 
20     <!-- 定义属性 -->
21     <properties>
22         <!-- 项目编码 -->
23         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
24         <!-- 时间格式 -->
25         <maven.build.timestamp.format>yyyyMMdd</maven.build.timestamp.format>
26     </properties>
27 
28     <!-- 依赖配置 -->
29     <dependencies>
30         ...
31         <dependency>
32             <groupId>xxx</groupId>
33             <artifactId>xxx</artifactId>
34             <version>x.x.x</version>
35         </dependency>
36         ...
37     </dependencies>
38 
39     <!-- 定义profile: 将开发配置和生产配置分离开 -->
40     <profiles>
41         <profile>
42             <id>dev</id>
43             <properties>
44                 <profile.dir>dev</profile.dir>
45             </properties>
46         </profile>
47         <profile>
48             <id>test</id>
49             <properties>
50                 <profile.dir>test</profile.dir>
51             </properties>
52         </profile>
53         <profile>
54             <id>prod</id>
55             <properties>
56                 <profile.dir>prod</profile.dir>
57             </properties>
58         </profile>
59     </profiles>
60 
61     <!-- 打包 -->
62     <build>
63         <finalName>xxx</finalName>
64         
65         <!-- 打包资源 -->
66         <resources>
67             <resource>
68                 <directory>src/main/java</directory>
69                 <excludes>
70                     <exclude>.svn</exclude>
71                     <exclude>.java</exclude>
72                 </excludes>
73             </resource>
74             <resource>
75                 <directory>src/main/resources/profiles/${profile.dir}</directory>
76                 <excludes>
77                     <exclude>.svn</exclude>
78                 </excludes>
79             </resource>
80         </resources>
81         
82         <!-- 配置打包插件,如: 依赖处理,资源复制,压缩打包等 -->
83         <plugins>
84             <plugin>
85                 ...
86             </plugin>
87         </plugins>
88     </build>
89 </project>
View Code

 

maven项目配置框架