@nalan90
2017-08-28T11:34:20.000000Z
字数 2287
阅读 534
Maven
环境搭建
## 下载安装包并解压
http://maven.apache.org/download.cgi
work:apache-maven-3.5.0 ys$ pwd
/Users/ys/Documents/apache-maven-3.5.0
work:apache-maven-3.5.0 ys$ ll
total 64
-rw-r--r--@ 1 ys staff 20934 Apr 4 03:41 LICENSE
-rw-r--r--@ 1 ys staff 182 Apr 4 03:40 NOTICE
-rw-r--r--@ 1 ys staff 2544 Apr 4 03:36 README.txt
drwxr-xr-x@ 8 ys staff 272 Aug 27 10:44 bin
drwxr-xr-x@ 3 ys staff 102 Aug 27 10:44 boot
drwxr-xr-x@ 5 ys staff 170 Apr 4 03:36 conf
drwxr-xr-x@ 83 ys staff 2822 Apr 4 03:41 lib
## 配置环境变量
work:~ ys$ tail .bash_profile
export MAVEN_HOME=/Users/ys/Documents/apache-maven-3.5.0
export PATH=$PATH:/usr/local/go/bin:$MAVEN_HOME/bin
## 更新环境变量
work:~ ys$ source .bash_profile
## 检测安装是否正确
work:maven ys$ mvn -v
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-04T03:39:06+08:00)
Maven home: /Users/ys/Documents/apache-maven-3.5.0
Java version: 1.8.0_111, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.12.6", arch: "x86_64", family: "mac"
常用命令
自动创建Maven项目目录结构
mvn archetype:generate
-DgroupId=com.imooc.maven04
-DartifactId=maven04-demo
-Dversion=1.0-SNAPSHOT
-Dpackage=com.imooc.maven04.demo
work:maven04-demo ys$ ll
total 8
-rw-r--r-- 1 ys staff 763 Aug 27 14:29 pom.xml
drwxr-xr-x 4 ys staff 136 Aug 27 14:29 src
work:maven ys$ tree maven04-demo/
maven04-demo/
├── pom.xml
└── src
├── main
│ └── java
│ └── com
│ └── imooc
│ └── maven04
│ └── demo
│ └── App.java
└── test
└── java
└── com
└── imooc
└── maven04
└── demo
└── AppTest.java
13 directories, 3 files
## 参数说明
groupId:组织名,公司网址的反写+项目名
artifactId:项目名-模块名
version:版本号
package:代码所在的包名
maven仓库
## Central Repository
http://search.maven.org/
## 修改镜像仓库地址
work:conf ys$ vim /Users/ys/Documents/apache-maven-3.5.0/conf/settings.xml
<mirror>
<id>maven.net.cn</id>
<mirrorOf>central</mirrorOf>
<name>Central Mirror In China.</name>
<url>http://maven.net.cn/content/groups/public</url>
</mirror>
## 修改本地仓库位置 (默认在当前用户下的.m2/目录下)
work:repository ys$ pwd
/Users/ys/.m2/repository
work:repository ys$ ll
total 0
drwxr-xr-x 3 ys staff 102 Aug 27 14:21 antlr
drwxr-xr-x 3 ys staff 102 Aug 21 17:21 aopalliance
......
drwxr-xr-x 3 ys staff 102 Aug 21 17:20 xmlenc
## 修改完成后,新下载的包会放置该目录下
work:conf ys$ vim /Users/ys/Documents/apache-maven-3.5.0/conf/settings.xml
<localRepository>/Users/ys/Documents/maven-repo</localRepository>