美文网首页mavenLinux学习之路
Linux系统下安装Maven

Linux系统下安装Maven

作者: 1204号技师 | 来源:发表于2017-11-22 23:56 被阅读13次

    本例子以apache-maven-3.5.2版本为例, 官网下载地址:Maven Download

    • 下载Maven
    cd /usr/lib
    wget http://mirror.bit.edu.cn/apache/maven/maven-3/3.5.2/binaries/apache-maven-3.5.2-bin.zip
    unzip apache-maven-3.5.2-bin.zip
    rm -rf apache-maven-3.5.2-bin.zip
    
    • 配置 Maven 环境 vim /etc/profile, 在文件末尾加上如下配置
    export MAVEN_HOME=/usr/lib/apache-maven-3.5.2
    export PATH=${PATH}:${MAVEN_HOME}/bin
    
    • 配置生效 . /etc/profile, 检查Maven 是否成功安装 mvn -v
    Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T00:58:13-07:00)
    Maven home: /usr/lib/apache-maven-3.5.2
    Java version: 1.8.0_151, vendor: Oracle Corporation
    Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/jre
    Default locale: en_US, platform encoding: UTF-8
    OS name: "linux", version: "3.10.0-514.el7.x86_64", arch: "amd64", family: "unix"
    
    • 修改默认配置 vim /usr/lib/apache-maven-3.5.2/conf/settings.xml
    • 修改默认仓库 <localRepository>${MAVEN_HOME}/.m2/repository</localRepository>
    • 配置国内的源, 在<mirrors>标签里添加
        <mirror>
          <id>nexus-aliyun</id>
          <mirrorOf>*</mirrorOf>
          <name>Nexus aliyun</name>
          <url>http://maven.aliyun.com/nexus/content/groups/public</url>
        </mirror>
    
        <mirror>
         <id>nexus-osc</id>
         <mirrorOf>*</mirrorOf>
         <name>Nexusosc</name>
         <url>http://maven.oschina.net/content/groups/public/</url>
        </mirror>
    
    • 修改JDK版本, 在<profiles>里添加
      <profile>
        <id>jdk1.8</id>
        <activation>
            <activeByDefault>true</activeByDefault>
            <jdk>1.8</jdk>
        </activation>
        <properties>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
            <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
        </properties>
       </profile>
    
    

    相关文章

      网友评论

        本文标题:Linux系统下安装Maven

        本文链接:https://www.haomeiwen.com/subject/rvlavxtx.html