[关闭]
@nalan90 2017-08-28T11:34:20.000000Z 字数 2287 阅读 534

Maven项目管理

Maven


环境搭建
  1. ## 下载安装包并解压
  2. http://maven.apache.org/download.cgi
  3. work:apache-maven-3.5.0 ys$ pwd
  4. /Users/ys/Documents/apache-maven-3.5.0
  5. work:apache-maven-3.5.0 ys$ ll
  6. total 64
  7. -rw-r--r--@ 1 ys staff 20934 Apr 4 03:41 LICENSE
  8. -rw-r--r--@ 1 ys staff 182 Apr 4 03:40 NOTICE
  9. -rw-r--r--@ 1 ys staff 2544 Apr 4 03:36 README.txt
  10. drwxr-xr-x@ 8 ys staff 272 Aug 27 10:44 bin
  11. drwxr-xr-x@ 3 ys staff 102 Aug 27 10:44 boot
  12. drwxr-xr-x@ 5 ys staff 170 Apr 4 03:36 conf
  13. drwxr-xr-x@ 83 ys staff 2822 Apr 4 03:41 lib
  14. ## 配置环境变量
  15. work:~ ys$ tail .bash_profile
  16. export MAVEN_HOME=/Users/ys/Documents/apache-maven-3.5.0
  17. export PATH=$PATH:/usr/local/go/bin:$MAVEN_HOME/bin
  18. ## 更新环境变量
  19. work:~ ys$ source .bash_profile
  20. ## 检测安装是否正确
  21. work:maven ys$ mvn -v
  22. Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-04T03:39:06+08:00)
  23. Maven home: /Users/ys/Documents/apache-maven-3.5.0
  24. Java version: 1.8.0_111, vendor: Oracle Corporation
  25. Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/jre
  26. Default locale: en_US, platform encoding: UTF-8
  27. OS name: "mac os x", version: "10.12.6", arch: "x86_64", family: "mac"

常用命令

自动创建Maven项目目录结构
  1. mvn archetype:generate
  2. -DgroupId=com.imooc.maven04
  3. -DartifactId=maven04-demo
  4. -Dversion=1.0-SNAPSHOT
  5. -Dpackage=com.imooc.maven04.demo
  6. work:maven04-demo ys$ ll
  7. total 8
  8. -rw-r--r-- 1 ys staff 763 Aug 27 14:29 pom.xml
  9. drwxr-xr-x 4 ys staff 136 Aug 27 14:29 src
  10. work:maven ys$ tree maven04-demo/
  11. maven04-demo/
  12. ├── pom.xml
  13. └── src
  14. ├── main
  15.    └── java
  16.    └── com
  17.    └── imooc
  18.    └── maven04
  19.    └── demo
  20.    └── App.java
  21. └── test
  22. └── java
  23. └── com
  24. └── imooc
  25. └── maven04
  26. └── demo
  27. └── AppTest.java
  28. 13 directories, 3 files
  29. ## 参数说明
  30. groupId:组织名,公司网址的反写+项目名
  31. artifactId:项目名-模块名
  32. version:版本号
  33. package:代码所在的包名

maven仓库
  1. ## Central Repository
  2. http://search.maven.org/
  3. ## 修改镜像仓库地址
  4. work:conf ys$ vim /Users/ys/Documents/apache-maven-3.5.0/conf/settings.xml
  5. <mirror>
  6. <id>maven.net.cn</id>
  7. <mirrorOf>central</mirrorOf>
  8. <name>Central Mirror In China.</name>
  9. <url>http://maven.net.cn/content/groups/public</url>
  10. </mirror>
  11. ## 修改本地仓库位置 (默认在当前用户下的.m2/目录下)
  12. work:repository ys$ pwd
  13. /Users/ys/.m2/repository
  14. work:repository ys$ ll
  15. total 0
  16. drwxr-xr-x 3 ys staff 102 Aug 27 14:21 antlr
  17. drwxr-xr-x 3 ys staff 102 Aug 21 17:21 aopalliance
  18. ......
  19. drwxr-xr-x 3 ys staff 102 Aug 21 17:20 xmlenc
  20. ## 修改完成后,新下载的包会放置该目录下
  21. work:conf ys$ vim /Users/ys/Documents/apache-maven-3.5.0/conf/settings.xml
  22. <localRepository>/Users/ys/Documents/maven-repo</localRepository>
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注