Maven·3rd(各种配置)

来源:互联网 发布:java单例模式好处 编辑:程序博客网 时间:2024/06/16 02:17

引言

本篇我们介绍,我们主要介绍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比较有效。

本地仓库路径配置

配置文件:%MAVEN_HOME%\confg\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