1. 程式人生 > 實用技巧 >Ubuntu20.04安裝 maven並配置阿里源

Ubuntu20.04安裝 maven並配置阿里源

Ubuntu20.04安裝 maven並配置阿里源

  1. sudo apt update
    
  2. sudo apt install maven #安裝maven,預設安裝路徑為/usr/share/maven
    
  3. 新增maven環境配置,在/etc/profile.d資料夾下新建配置檔案maven.sh

    vim /etc/profile.d/maven.sh
    

    maven.sh內容如下:

    export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 
    export M2_HOME=/usr/share/maven
    export MAVEN_HOME=/usr/share/maven
    export PATH=${M2_HOME}/bin:${PATH}
    
  4. 載入環境配置

    source /etc/profile.d/maven.sh
    
  5. maven本地倉庫初始化,在使用者家目錄下會生成一個.m2的資料夾

    sudo mvn help:system
    
  6. 拷貝setting.xml到.m2資料夾下

    cd ~/.m2
    cp ${MAVEN_HOME}/conf/settings.xml .
    
  7. 修改settings.xml檔案,配置阿里源

    sudo vim settings.xml
    
    <mirror>
          <id>alimaven</id>
          <name>aliyun maven</name>
          <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
          <mirrorOf>central</mirrorOf>
    </mirror>
    
  8. 測試

    mvn -v