欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

maven 安装配置 - vscode for java

程序员文章站 2022-06-01 12:06:19
...

该文档保留所有的链接地址

参考教程:

maven 官方网站:

Windows 安装步骤:

  1. 下载ZIP 文件
    点击直接下载
    https://mirror.bit.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip

  2. 解压到 自己的目录(因为我C盘富裕,所以解压到C:\Java) 文件夹下

  3. 该步骤推荐一下解压缩工具 bindzip
    (官网 https://www.bandisoft.com/bandizip/)
    (点击下载 https://www.bandisoft.com/bandizip/dl.php?online)

  4. 配置环境变量
    手动:(图像来自 菜鸟教程)

    maven 安装配置 - vscode for java
    maven 安装配置 - vscode for java

        MAVEN_HOME  
        C:\Java\apache-maven-3.6.3  
        PATH  
        %MAVEN_HOME%\bin  
        setx MAVEN_HOME "C:\Java\apache-maven-3.6.3" -M
    

    PowerShell:

    ## 设置系统环境变量 使用管理员打开powershell 
    [environment]::SetEnvironmentvariable("MAVEN_HOME","C:\Java\apache-maven-3.6.3","Machine")
    $path=[environment]::GetEnvironmentvariable("PATH", "Machine")
    [environment]::SetEnvironmentvariable("Path",$path+";%MAVEN_HOME%\bin","Machine")
    ## 查看环境变量
    [environment]::GetEnvironmentvariable("MAVEN_HOME", "Machine")
    [environment]::GetEnvironmentvariable("Path", "Machine")
    ## 重启计算机
    Restart-Computer
    
  1. 执行mvn -v查看安装结果
    PS F:\Java> mvn -v
    Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
    Maven home: C:\Java\apache-maven-3.6.3\bin\..
    Java version: 1.8.0_231, vendor: Oracle Corporation, runtime: C:\Java\jdk1.8.0_231\jre
    Default locale: zh_CN, platform encoding: GBK
    OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
    
  2. 配置vscode
    "java.home": "C:\\Java\\jdk1.8.0_231",
    "java.configuration.maven.userSettings": "C:\\Java\\apache-maven-3.6.3\\conf\\settings.xml",
    "maven.executable.path": "C:\\Java\\apache-maven-3.6.3\\bin\\mvn.cmd",
    "maven.terminal.useJavaHome": true,
    "maven.terminal.customEnv": [
        {
            "environmentVariable": "JAVA_HOME",
            "value": "C:\\Java\\jdk1.8.0_231"
        }
    ],
    
  3. 修改 maven 镜像仓库
    <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>        
    </mirror>
  1. 备注
    • 本地仓库
      Maven 的本地仓库,在安装 Maven 后并不会创建,它是在第一次执行 maven 命令的时候才被创建。

      运行 Maven 的时候,Maven 所需要的任何构件都是直接从本地仓库获取的。如果本地仓库没有,它会首先尝试从远程仓库下载构件至本地仓库,然后再使用本地仓库的构件。

      默认情况下,不管Linux还是 Windows,每个用户在自己的用户目录下都有一个路径名为 .m2/respository/ 的仓库目录。

      Maven 本地仓库默认被创建在 %USER_HOME% 目录下。要修改默认位置,在 %M2_HOME%\conf 目录中的 Maven 的 settings.xml 文件中定义另一个路径。

第一次创建Webapp 日志记录

PS F:\Java\helloworld\helloWebapp> & “C:\Java\apache-maven-3.6.3\bin\mvn.cmd” org.apache.maven.plugins:maven-archetype-plugin:3.1.2:generate -DarchetypeArtifactId=“maven-archetype-webapp” -DarchetypeGroupId=“org.apache.maven.archetypes” -DarchetypeVersion=“1.4”
[INFO] Scanning for projects…
Downloading from alimaven: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/plugins/maven-archetype-plugin/3.1.2/maven-archetype-plugin-3.1.2.pom
Downloaded from alimaven: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/plugins/maven-archetype-plugin/3.1.2/maven-archetype-plugin-3.1.2.pom (11 kB at 15 kB/s)
Downloading from alimaven: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/archetype/maven-archetype/3.1.2/maven-archetype-3.1.2.pom
Downloaded from alimaven: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/archetype/maven-archetype/3.1.2/maven-archetype-3.1.2.pom (12 kB at 27 kB/s)
Downloading from alimaven: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-parent/33/maven-parent-33.pom
Downloaded from alimaven: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/maven-parent/33/maven-parent-33.pom (44 kB at 154 kB/s)
Downloading from alimaven: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/apache/21/apache-21.pom
Downloaded from alimaven: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/apache/21/apache-21.pom (17 kB at 38 kB/s)
Downloading from alimaven: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/plugins/maven-archetype-plugin/3.1.2/maven-archetype-plugin-3.1.2.jar
Downloaded from alimaven: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/plugins/maven-archetype-plugin/3.1.2/maven-archetype-plugin-3.1.2.jar (97 kB at 186 kB/s)
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.1.2:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.1.2:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO]
[INFO] — maven-archetype-plugin:3.1.2:generate (default-cli) @ standalone-pom —
Downloading from alimaven: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/archetype/archetype-catalog/3.1.2/archetype-catalog-3.1.2.pom
Downloaded from alimaven: http://maven.aliyun.com/nexus/content/repositories/central/org/apache/maven/archetype/archetype-catalog/3.1.2/archetype-catalog-3.1.2.pom (2.0 kB at 7.9 kB/s)
Define value for property ‘groupId’: com.hello
Define value for property ‘artifactId’: main
Define value for property ‘version’ 1.0-SNAPSHOT: :
Define value for property ‘package’ com.hello: :
Confirm properties configuration:
groupId: com.hello
artifactId: main
version: 1.0-SNAPSHOT
package: com.hello
Y: : y
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: maven-archetype-webapp:1.4
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.hello
[INFO] Parameter: artifactId, Value: main
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: com.hello
[INFO] Parameter: packageInPathFormat, Value: com/hello
[INFO] Parameter: package, Value: com.hello
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: groupId, Value: com.hello
[INFO] Parameter: artifactId, Value: main
[INFO] Project created from Archetype in dir: F:\Java\helloworld\helloWebapp\main
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:45 min
[INFO] Finished at: 2020-04-09T22:47:32+08:00
HOT
[INFO] Parameter: groupId, Value: com.hello
[INFO] Parameter: artifactId, Value: main
[INFO] Project created from Archetype in dir: F:\Java\helloworld\helloWebapp\main
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:45 min
[INFO] Finished at: 2020-04-09T22:47:32+08:00
[INFO] ------------------------------------------------------------------------

相关标签: vscode java maven