Maven·3rd(各种配置)

引言

本篇我们介绍,我们主要介绍Maven中常用设定的配置方法

代理服务器配置

有时候我们本地执行Maven命令的时候,偶尔会发生如下error。
(https://repo.maven.apache.org/maven2): connect timed out

方法1:配置文件:C:\Users\【UserName】\.m2\settings.xml
在此文件中加入以下设定内容:

  <proxies>
      <proxy>
          <id>proxy</id><!--代理服务器ID(任意值)-->
          <active>true</active><!--true设定时候,表示当前此代理为激活状态-->
          <protocol>https</protocol><!--协议,http或https比较常用,在此推荐使用https-->
          <host>www.proxy.com</host><!--代理服务器地址(根据实际情况进行修改)-->
          <port>80</port><!--代理服务器端口(根据实际情况进行修改)-->
          <username>usr</username><!--代理服务器用户名(根据实际情况进行修改)-->
          <password>psw</password><!--代理服务器密码(根据实际情况进行修改)-->
          <!--指定访问哪些主机的时候,是不需要使用以上代理的,如果是多个主机地址需要指定的话,中间用“|”分割,并且可使用通配符-->
          <nonProxyHosts>localhost</nonProxyHosts>
      </proxy>
  </proxies>

方法2:配置文件:%MAVEN_HOME%\confg\settings.xml
在此文件中加入以下设定内容:

  <proxies>
      <proxy>
          <id>proxy</id><!--代理服务器ID(任意值)-->
          <active>true</active><!--true设定时候,表示当前此代理为激活状态-->
          <protocol>https</protocol><!--协议,http或https比较常用,在此推荐使用https-->
          <host>www.proxy.com</host><!--代理服务器地址-->
          <port>80</port><!--代理服务器端口-->
          <username>usr</username><!--代理服务器用户名-->
          <password>psw</password><!--代理服务器密码-->
          <!--指定访问哪些主机的时候,是不需要使用以上代理的,如果是多个主机地址需要指定的话,中间用“|”分割,并且可使用通配符-->
          <nonProxyHosts>localhost</nonProxyHosts>
      </proxy>
  </proxies>

※Eclipse使用Maven时,出现[connect timed out]的话,使用方法1比较有效。

本地仓库路径配置

配置文件:<%M2_HOME%>\conf\settings.xml
在此文件中加入以下设定内容:

<localRepository>
X:\your path\to your\maven repository
</localRepository>

远程仓库镜像的配置

默认远程仓库镜像地址:
%M2_HOME%\lib\maven-model-builder-X.Y.Z.jar
→ pom-4.0.0.xml
https://repo.maven.apache.org/maven2

配置文件:%MAVEN_HOME%\confg\settings.xml
在此文件中加入以下设定内容:
方法1:
在setting.xml中找到…………的位置。
在…………中间加入你想要的仓库的标签。

 <mirror>  
       <id>alimaven</id>  
       <mirrorOf>central</mirrorOf>  
       <name>aliyun maven</name>  
       <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>  
 </mirror>

方法2:配置文件:C:\Users\【UserName】.m2\settings.xml
在此文件中加入以下设定内容:

  <profiles>
     <profile>
         <id>dev</id>
         <repositories>
             <repository>
                 <id>Maven aliyun Mirror</id>
                 <name>Maven aliyun Mirror</name>
                 <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
                 <releases>
                     <enabled >true</enabled>
                 </releases>
                 <snapshots>
                     <enabled >false</enabled>
                 </snapshots>
             </repository>
         </repositories>
         <pluginRepositories>
             <pluginRepository>
                 <id>Maven aliyun Mirror</id>
                 <name>Maven aliyun Mirror</name>
                 <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
                 <releases>
                     <enabled>true</enabled>
                 </releases>
                 <snapshots>
                     <enabled>false</enabled>
                 </snapshots>
             </pluginRepository>
         </pluginRepositories>
     </profile>
 </profiles>
 <activeProfiles>
     <activeProfile>dev</activeProfile>
 </activeProfiles>

※方式2 适用Eclipse中设定需求。
※常用的国内远程仓库:
http://maven.aliyun.com/nexus/content/groups/public/
http://maven.aliyun.com/nexus/content/repositories/central/

参考文档
http://www.techscore.com/
https://qiita.com/tarosa0001/items/e5667cfa857529900216

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值