Maven配置阿里云仓库下载依赖「建议收藏」

Maven配置阿里云仓库下载依赖「建议收藏」用过Maven的都知道Maven的方便便捷,但由于某些网络原因,访问国外的Maven仓库不便捷,maven默认使用的是国外的中央仓库,下载jar时有时候会因为网络不好等原因下载不全或失败,好在国内像阿里云、网易、JBoos、开源中国等大厂搭建了国内的maven仓库,阿里云的maven仓库使用的比较多:需要使用的话,要在maven的settings.xml文件里配置mirrors的子节点,添加…

大家好,又见面了,我是你们的朋友全栈君。

一、前言

用过Maven的都知道Maven的方便便捷,但由于某些网络原因,访问国外的Maven仓库不便捷,maven默认使用的是国外的中央仓库,下载jar时有时候会因为网络不好等原因下载不全或失败,好在国内像阿里云、网易、JBoos、开源中国等大厂搭建了国内的maven仓库,这里阿里云的maven仓库使用的比较多。

二、配置国内Maven仓库

需要使用的话,要在maven的settings.xml 文件里配置mirrors的子节点,添加如下mirror:


<!-- 指定本地Maven仓库存储地址 -->	
<localRepository>D:\path\developTool\apache-maven\Repository\springboot_repository</localRepository>

<mirrors>
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->	 
	<!-- 阿里云镜像仓库地址 -->		
	<mirror>    
     <id>alimaven</id>    
     <name>aliyun maven</name>    
     <url>http://maven.aliyun.com/nexus/content/groups/public/</url>    
     <mirrorOf>central</mirrorOf> 	
    </mirror>    
	
	<!--JBoos镜像地址镜像仓库地址 -->	
	<mirror>
     <id>jboss-public-repository-group</id>
     <name>JBoss Public Repository Group</name>
     <url>http://repository.jboss.org/nexus/content/groups/public</url>
     <mirrorOf>central</mirrorOf>
    </mirror> 
		
  	<!--oschina镜像地址镜像仓库地址 -->	
	<mirror>
     <id>CN</id>
     <name>OSChina Central</name>
     <url>http://maven.oschina.net/content/groups/public/</url>
     <mirrorOf>central</mirrorOf>
    </mirror>

</mirrors>

这样,在导入新项目,或者创建项目的时候, 边可使用配置的maven仓库下载依赖,提高速度;

三、Maven的完整setting.xml配置

通过自己平常在使用Maven时总结的一些经验,下面贴出一份比较全的Maven的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">
 
 
  <!-- 指定本地Maven仓库地址 -->
  <localRepository>D:\path\developTool\apache-maven\Repository\springboot_repository</localRepository>
 

  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->

  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->

  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</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
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->

    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  </servers>

  
  <!-- 远程镜像仓库地址配置 -->
  <mirrors>
  
      <!-- 阿里云镜像仓库地址 -->   
    <mirror>  
     <id>nexus-aliyun</id>  
     <mirrorOf>central</mirrorOf>    
     <name>Nexus aliyun</name>  
     <url>http://maven.aliyun.com/nexus/content/groups/public</url>  
    </mirror> 
	  
	  <!--JBoos镜像地址镜像仓库地址 -->	
	<mirror>
     <id>jboss-public-repository-group</id>
     <name>JBoss Public Repository Group</name>
     <url>http://repository.jboss.org/nexus/content/groups/public</url>
     <mirrorOf>central</mirrorOf>
    </mirror> 
		
  	<!--oschina镜像地址镜像仓库地址 -->	
	<mirror>
     <id>CN</id>
     <name>OSChina Central</name>
     <url>http://maven.oschina.net/content/groups/public/</url>
     <mirrorOf>central</mirrorOf>
    </mirror>

  </mirrors>

  
  <!-- 配置: jdk1.8等, 先从阿里云下载, 没有再去私服下载  -->
  <profiles>
	
	    <!-- 全局JDK1.8配置、项目编码、项目编译jdk版本 -->
        <profile>
            <id>jdk1.8</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <jdk>1.8</jdk>
            </activation>
            <properties>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                <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>

		
		<!-- 企业内部Nexus私服仓库配置: 第三方jar包下载, 比如oracle的jdbc驱动等 -->
        <profile>
            <id>dev</id>
            <repositories>
                <repository>
                    <id>nexus</id>
                    <url>http://nexus.xxxxx.cn:8081/nexus/content/groups/public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>public</id>
                    <name>Public Repositories</name>
                    <url>http://nexus.xxxxx.cn:8081/nexus/content/groups/public/</url>
                </pluginRepository>
            </pluginRepositories>
        </profile>
		
		
		<!-- 阿里云配置: 提高国内的jar包下载速度 -->
	    <profile>    
		    <id>aliyun</id>
            <repositories>  
                <repository>  
                    <id>nexus</id>  
                    <name>local private nexus</name>  
                    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>  
                    <releases>  
                        <enabled>true</enabled>  
                    </releases>  
                    <snapshots>  
                        <enabled>false</enabled>  
                    </snapshots>  
                </repository>  
            </repositories>  
            <pluginRepositories>  
                <pluginRepository>  
                    <id>nexus</id>  
                    <name>local private nexus</name>  
                    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>  
                    <releases>  
                        <enabled>true</enabled>  
                    </releases>  
                    <snapshots>  
                        <enabled>false</enabled>  
                    </snapshots>  
                </pluginRepository>  
            </pluginRepositories>  
        </profile>  
	
  </profiles>

  <!-- 激活配置 --> 
  <activeProfiles> 
     <activeProfile>jdk1.8</activeProfile>  
     <activeProfile>dev</activeProfile>  
	 <activeProfile>aliyun</activeProfile> 
  </activeProfiles>
</settings>

四、Maven学习资料

Maven官方学习文档:http://maven.apache.org/guides/mini/guide-mirror-settings.html

 
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/150541.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • pytorch安装详细步骤[通俗易懂]

    pytorch安装详细步骤[通俗易懂]环境:win10+anaconda注:anaconda安装步骤略,以下步骤默认anaconda已安装。(三)安装pytorch3.1创建虚拟环境<1>打开anacondaprompt<2>打开AnacondaPrompt之后,在命令行输入:condacreate–namepytorchpython=3.8.1注意,这里的pytorch是虚拟环境的名称,可随意取。3.8.1是我机器上的python版本,可结合自己安装的python版本灵活

    2022年6月24日
    47
  • Java 最常见的 200+ 面试题:面试必备「建议收藏」

    这份面试清单是从我2015年做了TeamLeader之后开始收集的,一方面是给公司招聘用,另一方面是想用它来挖掘在Java技术栈中,还有那些知识点是我不知道的,我想找到这些技术盲点,然后修复它,以此来提高自己的技术水平。虽然我是从2009年就开始参加编程工作了,但我依旧觉得自己现在要学的东西很多,并且学习这些知识,让我很有成就感和满足感,那所以何乐而不为呢?说回面试的事,这份面试…

    2022年4月1日
    32
  • 验证码的作用,为什么要存在验证码[通俗易懂]

    验证码的作用,为什么要存在验证码[通俗易懂]攻击者攻击客户端的一些手法:1、在WEB站有时会碰到客户机恶意攻击,其中一种很常见的攻击手段就是“身份欺骗”,它通过在客户机端脚本写入一些代码,然后利用它,客户机在网站、论坛反复登录2、攻击者创建

    2022年7月1日
    23
  • ssm管理系统课题_p2实验室

    ssm管理系统课题_p2实验室开发目的方便高效地实验室设备统一管理,除了实现基本的增删改查,还提供借用、归还、购买和问题反馈功能,可实现对实验室设备的基本业务的处理本项目由本人负责开发完成,项目能保证正常运行,当然其中不免也会有缺漏或不完善的地方解决方案1.后端Java框架使用spring+springmvc+mybatisspring功能是实现参数参数注入,请求分发处理,对数据库操作进行事务控制,其中mybatis使用注解查询,整体上大部分使用xml配置,少部分使用注解2.前端使用HTML+javascript+css+j

    2022年10月13日
    0
  • 状态模式state_解释器模式

    状态模式state_解释器模式状态模式 State动机模式定义实例结构要点总结笔记动机在软件构建过程中,某些对象的状态如果改变,其行为也会随之而发生变化,比如文档处于只读状态,其支持的行为和读写状态支持的行为就可能不同.如何在运行时根据对象的状态来透明地更改对象的行为?而不会为对象操作和状态转换之间引入紧耦合模式定义允许一个对象在其内部状态改变时改变它的行为.从而使对象看起来似乎修改了其行为.从而使对象看起来似乎修改了其行为.从而使对象看起来似乎修改了其行为.实例朴素根据状态来执行下一步enum NetworkStat

    2022年8月9日
    3
  • PAT乙级1004

    PAT乙级10041004.成绩排名(20)时间限制400ms内存限制65536kB代码长度限制8000B判题程序Standard作者CHEN,Yue读入n名学生的姓名、学号、成绩,分别输出成绩最高和成绩最低学生的姓名和学号。输入格式:每个测试输入包含1个测试用例,格式为第1行:正整数n第2行:第1个学生的姓名学号成绩第3行:第2个学生的姓名学号成绩…………

    2022年6月3日
    36

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号