Maven安装详解+本地仓库路径配置

该文详细介绍了在Windows10系统中安装和配置Maven的步骤,包括下载Maven安装包,设置Maven的环境变量,检查安装成功,以及修改本地仓库位置。此外,还讲解了如何配置Maven使用Nexus私有服务器,通过修改settings.xml文件来设定仓库地址和认证信息。
摘要由CSDN通过智能技术生成

一、准备工作

1、确定电脑上已经成功安装jdk7.0以上版本

2、win10操作系统

3、maven安装包

下载地址:Maven – Download Apache Maven

二、解压Maven安装包

在上述地址中下载最新的Maven版本,解压到指定目录(此处根据自己的需要),本人解压到了D:\install\maven\apache-maven-3.5.0目录下,里面有bin、lib conf等文件夹。

三、配置Maven环境变量

在我的电脑-------属性-------高级系统设置---------环境变量---------系统变量--------新建

变量名:M2_HOME

变量值:D:\install\maven\apache-maven-3.5.0

找到Path在环境变量值尾部加入:;%M2_HOME%\bin; //前面注意分号

四、检查jdk和maven的环境变量是否配置成功

打开dos窗口运行命令mvn -v,出现如下图所示的信息说明安装成功;

五、修改本地仓库位置(如果不想修改本地仓库位置则这一步骤省略即可)

Maven会将下载的类库(jar包)放置到本地的一个目录下(一般默认情况下maven在本机的仓库位于C:\我的文档中\.m2.\repository),如果想重新定义这个目录的位置就需要修改Maven本地仓库的配置:

1、在自己喜欢的位置创建文件夹,此处本人创建的位置是(D:\maven\repository)

2、在安装Maven的目录下找到conf文件夹,在文件夹中找到settings.xml文件,复制settings.xml文件放于D:\maven\repository,如下图所示:

3、修改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:\maven\repository</localRepository>

4、在安装Maven的目录下找到conf文件夹,在文件夹中找到settings.xml文件,更改默认的仓库位置如下图所示:(注意两个地方的settings.xml都要修改)

依据该配置,Maven就会将下载的类库保存到D:\maven\repository中。

六、Maven配置使用Nexus

修改setting.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:\maven\repository</localRepository>
  <pluginGroups>
    <pluginGroup>org.mortbay.jetty</pluginGroup>
  </pluginGroups>

  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>

  <servers>
    <server>
      <id>nexus3</id>
      <username>admin</username>
      <password>admin</password>
    </server>
    <server>
      <id>releases</id>
      <username>admin</username>
      <password>admin</password>
    </server>
    <server>
      <id>snapshots</id>
      <username>admin</username>
      <password>admin</password>
    </server>
  </servers>

  <mirrors>
    <mirror>
      <id>nexus3</id>
      <mirrorOf>*</mirrorOf>
      <name>nexus3</name>
      <url>http://私有服务器IP:8081/repository/my-public/</url>
    </mirror>
  </mirrors>

  <profiles>
    <profile>
      <!--profile的id -->
      <id>nexus</id>
      <repositories>
        <repository> <!--仓库id,repositories可以配置多个仓库,保证id不重复 -->
          <id>nexus</id> <!--仓库地址,即nexus仓库组的地址 -->
          <url>http://私有服务器IP:8081/repository/my-public/</url> <!--是否下载releases构件 -->
          <releases>
            <enabled>true</enabled>
          </releases> <!--是否下载snapshots构件 -->
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories> <!-- 插件仓库,maven的运行依赖插件,也需要从私服下载插件 -->
        <pluginRepository> <!-- 插件仓库的id不允许重复,如果重复后边配置会覆盖前边 -->
          <id>public</id>
          <name>Public Repositories</name>
          <url>http://私有服务器IP:8081/repository/my-public/</url>
        </pluginRepository>
      </pluginRepositories>
    </profile>
        <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>
  
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

huangdi7

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值