Maven安装

Maven安装

1、Linux下Maven安装

1.1 下载安装包

maven 官网地址:https://maven.apache.org/download.cgi

安装包下载地址:https://dlcdn.apache.org/maven/maven-3

这里下载 apache-maven-3.3.9-bin.tar.gz

下载后上传到Linux服务器

1.2 安装Maven

解压 maven 安装包到 maven 文件夹:

$ mkdir -p /home/zhangshixing/maven
$ tar -zxvf apache-maven-3.3.9-bin.tar.gz -C /home/zhangshixing/maven

创建 maven 资源库目录:

$ mkdir -p /home/zhangshixing/maven/m2/repository

编辑 settings.xml 文件:

$ cd /home/zhangshixing/maven/apache-maven-3.3.9/conf/
$ vim settings.xml

将原文件内容全部删除,添加新的配置内容,删除命令:

:1,.d

新的配置内容,修改了资源库位置,添加了阿里云国内镜像:

<?xml version="1.0" encoding="UTF-8"?>
<settings
    xmlns="http://maven.apache.org/SETTINGS/1.2.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
    <localRepository>/home/zhangshixing/maven/m2/repository</localRepository>
    <pluginGroups></pluginGroups>
    <proxies></proxies>
    <servers></servers>
    <mirrors>
        <mirror>
            <id>alimaven</id>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
    </mirrors>
    <profiles></profiles>
</settings>

1.3 添加环境变量

vim /etc/profile

添加 maven 环境变量内容

MAVEN_HOME=/home/zhangshixing/maven/apache-maven-3.3.9
PATH=$MAVEN_HOME/bin:$PATH
export MAVEN_HOME PATH

重新加载配置文件

source /etc/profile

1.4 测试

$ mvn -version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: /home/zhangshixing/maven/apache-maven-3.3.9
Java version: 11.0.17, vendor: Red Hat, Inc.
Java home: /usr/lib/jvm/java-11-openjdk-11.0.17.0.8-2.el7_9.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1160.80.1.el7.x86_64", arch: "amd64", family: "unix"

2、Windows下Maven安装

安装包下载地址:https://dlcdn.apache.org/maven/maven-3

这里下载 apache-maven-3.3.9-bin.zip

2.1 解压安装包

下载安装包之后将安装包解压到 D:\DecompressionSoftwareInstall目录。

解压之后的目录:D:\DecompressionSoftwareInstall\apache-maven-3.3.9-bin

2.2 新建本地仓库

新建仓库目录:D:\DecompressionSoftwareInstall\apache-maven-3.3.9-bin\repository

2.3 修改配置文件配置远程仓库和本地仓库

修改 D:\DecompressionSoftwareInstall\apache-maven-3.3.9-bin\conf\settings.xml配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<settings
    xmlns="http://maven.apache.org/SETTINGS/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <localRepository>D:\DecompressionSoftwareInstall\apache-maven-3.3.9-bin\repository</localRepository>
    <pluginGroups></pluginGroups>
    <proxies></proxies>
    <servers></servers>
    <mirrors>
        <mirror>
            <id>alimaven</id>
            <mirrorOf>central</mirrorOf>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
        </mirror>
    </mirrors>
    <profiles>
        <profile>
            <id>jdk-1.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>
    </profiles>
</settings>

2.4 配置环境变量

配置环境变量:

M2_HOME = D:\DecompressionSoftwareInstall\apache-maven-3.3.9-bin

2.5 查看版本

$ mvn -v
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: D:\DecompressionSoftwareInstall\apache-maven-3.3.9-bin
Java version: 1.8.0_77, vendor: Oracle Corporation
Java home: D:\OwnerSoftwareInstall\jdk\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 10", version: "10.0", arch: "amd64", family: "dos"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值