1. 问题描述

公司内网搭建的有maven私有服务器,但是碰到好几次只有gav没有jar的情况或者最新版本更新不及时,所以需要公司服务器和远程仓库(阿里云)相结合来满足项目需求。

2. 解决方案:

maven仓库配置主要两种方式,一种是全局的;一种是配置在项目中,局部的。

2.1 方式一,全局配置

直接更改repo中的setting,目前项目中正在使用(隐藏替换了公司服务器地址)。

直接上代码

<?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>E:\Develop\maven_repo</localRepository> -->
<localRepository>E:\m2\repository</localRepository>
<servers>
<server>
<id>releases</id>
<username>admin</username>
<password>admin@123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin@123</password>
</server>
</servers>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://dev.hbusy.com/maven/content/repositories/public</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository>
<id>cloudera</id>
<url>https://repository.cloudera.com/artifactory/clouderarepos/</url>
</repository>
<!--新增阿里云-->
<repository>
<id>aliyun</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://dev.hbusy.com/maven/content/repositories/public</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>aliyun</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository> </pluginRepositories>
</profile> </profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>

配置解析:

Maven 依赖搜索顺序:本地仓库->中央仓库->远程仓库。

1.本地仓库指定

<localRepository>E:\m2\repository</localRepository>

2. 国内一般直接用远程仓库(阿里云)

 <url>http://maven.aliyun.com/nexus/content/groups/public/</url>

3. 多仓库配置

  1. 配置多个repository
   <repositories>
<repository>
<id>aliyun</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</repository>
</repositories>
  1. 在pluginRepository中配置下对应的repository即可
  </pluginRepository>

                   <pluginRepository>
<id>aliyun</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>

2.2 方式二,项目中局部配置

<project>
<repositories>
<repository>
<id>central</id>
<url>http://dev.hbusy.com/maven/content/repositories/public</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository>
<id>cloudera</id>
<url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
</repository>
<!--新增阿里云-->
<repository>
<id>aliyun</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</repository>
</repositories>
</project>

​ 实际开发过程中,一般使用全局配置(在repo中配置setting),除非有些新老项目共存的情况,jar包存在冲突,会单独在项目中配置下。


maven多仓库配置(公司服务器与阿里云仓库)的更多相关文章

  1. Maven多仓库配置(公司仓库和阿里云仓库)

    Maven多仓库配置(公司仓库和阿里云仓库) 一.之前的配置 之前maven本地的setting.xml的仓库配置,都是直接设置mirror节点 <mirrors> <mirror& ...

  2. maven配置阿里云仓库进行下载

    maven阿里云仓库下载 为了解决maven在下载jar包的时候,速度比较慢的问题,可以配置阿里云仓库配置方式的进行下载,首先找到您安装的maven路径. 在conf文件夹下面有个settings.x ...

  3. 在Maven项目中,指定使用阿里云仓库下载jar包

    Maven项目中,在pom.xml的</project>标签之前加入一下标签,指定使用阿里云仓库下载jar包. <!-- 使用aliyun maven --> <repo ...

  4. 更改maven下载jar的仓库为阿里云仓库

    修改settings.xml <!-- 配置本地maven的仓库 --> <localRepository>D:\file\path\maven\repository</ ...

  5. 将Maven镜像更换为国内阿里云仓库

    1.国内访问maven默认远程中央镜像特别慢 2.用阿里的镜像替代远程中央镜像 3.大部分jar包都可以在阿里镜像中找到,部分jar包在阿里镜像中没有,需要单独配置镜像 换为国内镜像,让你感受飞一般的 ...

  6. [Java] Spring boot 的maven设置阿里云仓库

    Spring boot 的maven设置阿里云仓库 打开根目录下的 pom.xml 文件,在对应为止出加入如下 红色 代码: <build> <plugins> <plu ...

  7. Maven 阿里云仓库地址

    https://maven.aliyun.com/mvn/view 一般使用聚合仓库(group),path是仓库地址.可点击右上角“使用指南”: 附   目前阿里云仓库的地址 https://mav ...

  8. clojure 使用阿里云仓库

    clojure 使用阿里云仓库 学习一门语言,如果没有梯子真的是一件非常痛苦的事情,好在阿里巴巴为我们java程序员提供了maven镜像.近期学习clojure,为了找解决方案在stackoverfl ...

  9. Linux下配置yum源为阿里云或网易的详解

    一.yum源概述 yum需要一个yum库,也就是yum源.默认情况下,CentOS就有一个yum源.在/etc/yum.repos.d/目录下有一些默认的配置文件(可以将这些文件移到/opt下,或者直 ...

随机推荐

  1. EPPlus导出两千万行记录到xlsx的c#代码

    private void button5_Click(object sender, EventArgs e) { Stopwatch watch = new Stopwatch(); Backgrou ...

  2. 操作XML文档遇到的XMLNS问题及解决方法 (C# 和 PHP)

    原文:操作XML文档遇到的XMLNS问题及解决方法 (C# 和 PHP) 不管是用 PHP 还是 C#, 在操作 XML 的时候我们除了一个节点一个节点去取值之外, 还有一个非常方便的表达式, 就是 ...

  3. 零元学Expression Blend 4 &ndash; Chapter 43 如何指定Childwindow PopUp位置

    原文:零元学Expression Blend 4 – Chapter 43 如何指定Childwindow PopUp位置 有网友询问我有关Childwindow是否能指定弹出位置? 其实只要透过小小 ...

  4. delphi程序向另一个可执行程序发消息(使用GetForegroundWindow; 找出当前操作系统中活动的第一个窗口)

    function FindWindowThroughWindowText(WindowText: string): THandle;var  hCurrentWindow: THandle;  cnt ...

  5. DBShop 电子商务网店系统

    DBShop 电子商务网店系统,采用业界知名框架 ZendFramework 2 开发而成. 下面为功能简介 1.在线更新:在线系统更新和在线模板安装与更新,简单.方便.快捷,省却了手动更新的繁琐步骤 ...

  6. Windows系统版本判定那些事儿(有图,各种情况,很清楚)

    前言 本文并不是讨论Windows操作系统的版本来历和特点,也不是讨论为什么没有Win9,而是从程序员角度讨论下Windows获取系统版本的方法和遇到的一些问题.在Win8和Win10出来之后,在获取 ...

  7. 针对TianvCms的搜索优化文章源码(无版权, 随便用)

    介绍: 搜索优化虽然不是什么高深的技术, 真正实施起来却很繁琐, 后台集成搜索优化的文章可以便于便于管理, 也让新手更明白优化的步奏以及优化的日常. 特点: 根据自己的经验和查阅各种资料整理而成, 相 ...

  8. Spring特点

    1.非侵入式所谓非侵入式是指,Spring框架的API不会在业务逻辑上出现,即业务逻辑是POJO(Plain Old Java Objects).由于业务逻辑中没有Spring的API,所以业务逻辑可 ...

  9. Tido 习题-二叉树-最高分

    题目描述 老师想知道从某某同学到某某同学当中,分数最高的是多少.现在请你编程模拟老师的询问.当然,老师有时候需要更新某位同学的成绩. 输入 输入包含多组测试数据.每组输入第一行是两个正整数N和M(0& ...

  10. 拉格朗日乘子法 - KKT条件 - 对偶问题

    接下来准备写支持向量机,然而支持向量机和其他算法相比牵涉较多的数学知识,其中首当其冲的就是标题中的拉格朗日乘子法.KKT条件和对偶问题,所以本篇先作个铺垫. 大部分机器学习算法最后都可归结为最优化问题 ...