-
Notifications
You must be signed in to change notification settings - Fork 1
/
maven learn note.txt
97 lines (70 loc) · 2.4 KB
/
maven learn note.txt
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
1.maven 安装
mvn -v 测试安装结果
2.新建hello world 工程
mvn archetype:generate -DgroupId=com.mycompany.helloworld -DartifactId=helloworld -Dpackage=com.mycompany.helloworld -Dversion=1.0-SNAPSHOT
3.新建成功之后,编译jar包
cd helloworld
mvn package
4.运行生成的jar包
java -cp target/helloworld-1.0-SNAPSHOT.jar com.mycompany.helloworld.App
POM (Project Object Model)
maven 坐标
groupId:artifactId:packaging:version
ex.
com.mycompany.helloworld: helloworld: jar: 1.0-SNAPSHOT
Maven 生命周期
process-resources 阶段:resources:resources
compile 阶段:compiler:compile
process-classes 阶段:(默认无目标)
process-test-resources 阶段:resources:testResources
test-compile 阶段:compiler:testCompile
test 阶段:surefire:test
prepare-package 阶段:(默认无目标)
package 阶段:jar:jar
pre-clean
clean
post-clean
mvn archetype:generate
archetype 是一个插件的名字,generate是目标(goal)的名字。这个命令的意思是告诉 maven 执行 archetype 插件的 generate 目标。插件目标通常会写成 pluginId:goalId
将构建的jar包安装到本地库
mvn install
maven依赖使用
<dependencies>
<dependency>
<groupId>com.mycompany.helloworld</groupId>
<artifactId>helloworld</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependencies>
引用本地jar
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5-SNAPSHOT</version>
<scope>system</scope>
<!--本地jar的路径,相对或者绝对都可以-->
<systemPath>/Users/nonkr/uyun-collector/lib/commons-io-2.5-20151119.212356-154.jar</systemPath>
</dependency>
添加mvn 仓库
<repositories>
<repository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
</repositories>
scope 决定了依赖关系的适用范围
查看POM 的全部内容
mvn help:effective-pom
查看maven环境变量
mvn help:system