maven是规定了一种项目代码布局格式,maven按照这种格式进行代码管理、依赖jar管理、单元测试、资管管理、编译管理、发布管理。
maven的核心是mvn命令和pom.xml文件
pom.xml文件作为maven和核心之一,对其语法使用总结如下:
1.properties关键字:项目的全局属性,如打包需要的编码
1
2
3
4
5
|
<properties>
<project.build.sourceEncoding>UTF-
8
</project.build.sourceEncoding>
</properties>
|
2.repositories关键字:配置仓库的http服务路径,可以是本地私服、也可以是网络服务器私服、或者官方服务器,有顺序
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
<repositories>
<repository>
<id>build.local.libs</id>
<url>http:
//build.local:8081/artifactory/libs-release-local</url>
<layout>
default
</layout>
</repository>
<repository>
<id>build.local.ext</id>
<url>http:
//build.local:8081/artifactory/ext-release-local</url>
</repository>
<repository>
<id>morphia.local</id>
<name>build.local-releases</name>
<url>http:
//build.local:8081/artifactory/morphia</url>
</repository>
</repositories>
|
3.dependencies关键字:所有的依赖jar信息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>
4.8
.
2
</version>
<scope>test</scope>
</dependency>
</dependencies>
|
4.内部项目公共jar包发布
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<distributionManagement>
<repository>
<id>local-artifactory</id>
<name>build.local-releases</name>
<url>http:
//build.local:8081/artifactory/libs-release-local</url>
</repository>
</distributionManagement>
|
5.项目profile配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
<profiles>
<profile>
<id>dist</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>
2.0
.
2
</version>
<configuration>
<source>
1.6
</source>
<target>
1.6
</target>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>
8.0
.
1
.v20110908</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>
package
</phase>
<goals>
<goal>attached</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<profile>
<id>sun.jdk</id>
<activation>
<property>
<name>java.vendor</name>
<value>Sun Microsystems Inc.</value>
</property>
</activation>
<properties>
<toolsjar>C:/Program Files/Java/jdk1.
6
.0_45/lib/tools.jar</toolsjar>
</properties>
</profile>
<profile>
<id>
default
-tools.jar</id>
<activation>
<property>
<name>java.vendor</name>
<value>Sun Microsystems Inc.</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>
1.5
.
0
</version>
<scope>system</scope>
<!-- 此处根据实际配置 -->
<systemPath>C:/Program Files/Java/jdk1.
6
.0_45/lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>
|
build设置:
Goals:clean install assembly:assembly
Profiles:dist