macbook Maven 下载 解压 配置 使用

Dear 丶 2022-10-17 11:13 313阅读 0赞

文章目录

    • 下载 && 解压
    • 配置文件修改
    • 环境变量配置
    • 使用测试

下载 && 解压

在官网:http://maven.apache.org/download.cgi
下载 https://mirrors.bfsu.edu.cn/apache/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.zip
在这里插入图片描述
解压到指定目录(我是~/javaweb/) unzip apache-maven-3.8.1-bin.zip -d ~/javaweb/

查看该目录下的内容:

在这里插入图片描述文本格式:

  1. leung@wuyujin ~ % ls -alG ~/javaweb
  2. total 0
  3. drwxr-xr-x 4 leung staff 128 6 2 22:20 .
  4. drwxr-xr-x+ 38 leung staff 1216 6 2 22:03 ..
  5. drwxr-xr-x 9 leung staff 288 11 7 2019 apache-maven-3.8.1
  6. drwxr-xr-x 2 leung staff 64 6 2 22:20 mvnrepo
  7. leung@wuyujin ~ % ls -alG ~/javaweb/apache-maven-3.8.1
  8. total 64
  9. drwxr-xr-x 9 leung staff 288 11 7 2019 .
  10. drwxr-xr-x 4 leung staff 128 6 2 22:20 ..
  11. -rw-r--r-- 1 leung staff 17504 11 7 2019 LICENSE
  12. -rw-r--r-- 1 leung staff 5141 11 7 2019 NOTICE
  13. -rw-r--r-- 1 leung staff 2612 11 7 2019 README.txt
  14. drwxr-xr-x 8 leung staff 256 11 7 2019 bin
  15. drwxr-xr-x 4 leung staff 128 11 7 2019 boot
  16. drwxr-xr-x 6 leung staff 192 6 2 22:11 conf
  17. drwxr-xr-x 65 leung staff 2080 11 7 2019 lib
  18. leung@wuyujin ~ %

这熟悉的目录结构。

配置文件修改

见 Maven settings.xml 配置项

环境变量配置

只是为了在任意目录都可以直接使用mvn命令(且不需要输入命令的全路径)。
本步骤可省略

配置项:

  1. export MVN_HOME=/Users/leung/javaweb/apache-maven-3.8.1
  2. export PATH=$MVN_HOME/bin:$PATH

将其写入当前用户、当前shell的配置文件中,我的是~/.zshrc

写入后保存,重载配置文件,使之生效:source ~/.zshrc

查看配置是否生效:

  1. leung@wuyujin ~ % echo $MVN_HOME
  2. /Users/leung/javaweb/apache-maven-3.8.1
  3. leung@wuyujin ~ % echo $PATH
  4. /Users/leung/javaweb/apache-maven-3.8.1/bin:/System/Volumes/Data/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
  5. leung@wuyujin ~ % where mvn
  6. /Users/leung/javaweb/apache-maven-3.8.1/bin/mvn
  7. leung@wuyujin ~ % mvn --version
  8. Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
  9. Maven home: /Users/leung/javaweb/apache-maven-3.8.1
  10. Java version: 1.8.0_291, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre
  11. Default locale: zh_CN, platform encoding: UTF-8
  12. OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"
  13. leung@wuyujin ~ %

使用测试

其实可以在命令行直接使用maven命令新建不同类型的java项目。

新建一个web项目mvn archetype:generate -DgroupId=com.wuyujin -DartifactId=webdemo -DarchetypeArtifactId=maven-archetype-webapp

  1. leung@wuyujin coderepo % mvn archetype:generate -DgroupId=com.wuyujin -DartifactId=webdemo -DarchetypeArtifactId=maven-archetype-webapp
  2. [INFO] Scanning for projects...
  3. [INFO]
  4. [INFO] ------------------< org.apache.maven:standalone-pom >-------------------
  5. [INFO] Building Maven Stub Project (No POM) 1
  6. [INFO] --------------------------------[ pom ]---------------------------------
  7. [INFO]
  8. [INFO] >>> maven-archetype-plugin:3.2.0:generate (default-cli) > generate-sources @ standalone-pom >>>
  9. [INFO]
  10. [INFO] <<< maven-archetype-plugin:3.2.0:generate (default-cli) < generate-sources @ standalone-pom <<<
  11. [INFO]
  12. [INFO]
  13. [INFO] --- maven-archetype-plugin:3.2.0:generate (default-cli) @ standalone-pom ---
  14. [INFO] Generating project in Interactive mode
  15. [WARNING] No archetype found in remote catalog. Defaulting to internal catalog
  16. Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/archetypes/maven-archetype-webapp/1.0/maven-archetype-webapp-1.0.pom
  17. Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/archetypes/maven-archetype-webapp/1.0/maven-archetype-webapp-1.0.pom (533 B at 416 B/s)
  18. Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/archetypes/maven-archetype-bundles/2/maven-archetype-bundles-2.pom
  19. Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/archetypes/maven-archetype-bundles/2/maven-archetype-bundles-2.pom (1.5 kB at 1.6 kB/s)
  20. Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/archetype/maven-archetype-parent/1/maven-archetype-parent-1.pom
  21. Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/archetype/maven-archetype-parent/1/maven-archetype-parent-1.pom (1.3 kB at 1.4 kB/s)
  22. Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/maven-parent/4/maven-parent-4.pom
  23. Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/maven-parent/4/maven-parent-4.pom (10.0 kB at 10 kB/s)
  24. Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/apache/3/apache-3.pom
  25. Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/apache/3/apache-3.pom (3.4 kB at 4.1 kB/s)
  26. Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/archetypes/maven-archetype-webapp/1.0/maven-archetype-webapp-1.0.jar
  27. Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/archetypes/maven-archetype-webapp/1.0/maven-archetype-webapp-1.0.jar (3.9 kB at 3.3 kB/s)
  28. [INFO] Using property: groupId = com.wuyujin
  29. [INFO] Using property: artifactId = webdemo
  30. Define value for property 'version' 1.0-SNAPSHOT: :
  31. [INFO] Using property: package = com.wuyujin
  32. Confirm properties configuration:
  33. groupId: com.wuyujin
  34. artifactId: webdemo
  35. version: 1.0-SNAPSHOT
  36. package: com.wuyujin
  37. Y: : y
  38. [INFO] ----------------------------------------------------------------------------
  39. [INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-webapp:1.0
  40. [INFO] ----------------------------------------------------------------------------
  41. [INFO] Parameter: basedir, Value: /Users/leung/javaweb/coderepo
  42. [INFO] Parameter: package, Value: com.wuyujin
  43. [INFO] Parameter: groupId, Value: com.wuyujin
  44. [INFO] Parameter: artifactId, Value: webdemo
  45. [INFO] Parameter: packageName, Value: com.wuyujin
  46. [INFO] Parameter: version, Value: 1.0-SNAPSHOT
  47. [INFO] project created from Old (1.x) Archetype in dir: /Users/leung/javaweb/coderepo/webdemo
  48. [INFO] ------------------------------------------------------------------------
  49. [INFO] BUILD SUCCESS
  50. [INFO] ------------------------------------------------------------------------
  51. [INFO] Total time: 16.377 s
  52. [INFO] Finished at: 2021-06-02T22:49:59+08:00
  53. [INFO] ------------------------------------------------------------------------
  54. leung@wuyujin coderepo %

接下来在命令行完成install和package, run jar.

  1. cd webdemo
  2. mvn install
  3. mvn package

package 动作会生成一个 war
该 wat 放置到 tomcat/jetty 等servlet容器中就可以运行/访问。

当执行过mvn archetype:generate -DgroupId=com.wuyujin -DartifactId=webdemo -DarchetypeArtifactId=maven-archetype-webapp之后,
会生成webdemo,其中有pom.xml以及src/目录及src/目录下的默认源码。

mvn install 会生成 target/目录及其下内容。

在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,313人围观)

还没有评论,来说两句吧...

相关阅读