写的非常好关于maven仓库的迁移(如果在大型公司 中央仓库直接可以改成自己公司中央仓库 不需要apache和alibaba))


如何修改仓库位置:
    修改本地仓库位置使其不在c盘下(一般默认在C:\Users\Administrator\.m2\repository
    为了使重装系统时不需要重新下载依赖包,可以将仓库设置在其它位置,方法如下
    首先,在新位置建立新文件夹当作新仓库,用来存放下载的依赖包,这里假设我新建了repos来代替原来的 repository,我的具体路径(根据自己存放位置) :D:\Maven\repos
    然后,从maven安装目录的conf下拷贝settings.xml到 D:\Maven路径下。
    (这里说明下settings.xml文件里,打开后可以看到
  1. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"  
  2.           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.           xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">  
  4.   <!-- localRepository  
  5.    | The path to the local repository maven will use to store artifacts.  
  6.    |  
  7.    | Default: ${user.home}/.m2/repository  
  8.   <localRepository>/path/to/local/repo</localRepository>  
  9.   -->  
<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
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
这里设置了默认仓库位置为.m2/repository,也就是刚才说的c盘那个位置

    之后,为了让它把仓库位置指向新位置,需要把conf下的settings.xml以及刚才拷贝的settings.xml里上面那段配置下新增自定义路径,以覆盖原路径
    如下:
  1. <localRepository>D:\Maven\repos</localRepository>  
<localRepository>D:\Maven\repos</localRepository>
这样,新的仓库位置就设置好了。
这时你也可以把原来仓库 repository下的所有已下载的文件全拷贝到新仓库下

中央工厂:
在maven安装目录下的lib下找到maven-model-builder-3.3.9的jar包,解压它,可以找到pom-4.0.xml文件,打开后,可以看到其中一段代码如下:
  1. <repositories>  
  2.  <repository>  
  3. <id>central</id>  
  4. <name>Central Repository</name>  
  5. <url>https://repo.maven.apache.org/maven2</url>  
  6. <layout>default</layout>  
  7.  <snapshots>  
  8. <enabled>false</enabled>  
  9. </snapshots>  
  10. </repository>  
  11. </repositories>  
<repositories>
 <repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
 <snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

url:https://repo.maven.apache.org/maven2即为中央工厂的网址,访问后可以搜查任一jar包的相关坐标信息


这是默认的中央仓库地址


或者访问:http://mvnrepository.com/


当然,中央仓库在国外,所以下载包的速度会很慢,所以可以自己配置镜像下载地址,之前有个oschina ,不过已经挂了,最近阿里云悄悄公开了一个maven中央仓库,速度很快。配置如下:
在maven跟目录下的conf文件夹中的setting.xml
打开,找到mirrors,添加如下:
  1. <mirrors>  
  2.   <mirror>  
  3.     <id>alimaven</id>  
  4.     <name>aliyun maven</name>  
  5.     <url>http://maven.aliyun.com/nexus/content/groups/public/</url>  
  6.     <mirrorOf>central</mirrorOf>          
  7.   </mirror>  
  8. </mirrors>  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值