7. Maven仓库
概述
maven仓库就是用来存储jar
包的,在maven中,这个jar
称之为构件
,每个构件都有自己的坐标。
maven仓库根据坐标进行定位构件步骤:
- 从
settings.xml
配置文件中,找localRepository
- 根据坐标拼接路径
groupId+artifiedId+version
找到构件的目录 - 根据
artifiedId+version+packaging
找到文件
maven仓库是分级的,有本地仓库和远程仓库,远程仓库又包含:私服、公共仓库、中央仓库
阿里云仓库配置
仓库服务
仓库名称
阿里云仓库地址
阿里云仓库地址(老版)
源地址
central
https://maven.aliyun.com/repository/central
https://maven.aliyun.com/nexus/content/repositories/central
https://repo1.maven.org/maven2/
jcenter
https://maven.aliyun.com/repository/public
https://maven.aliyun.com/nexus/content/repositories/jcenter
http://jcenter.bintray.com/
public
https://maven.aliyun.com/repository/public
https://maven.aliyun.com/nexus/content/groups/public
central仓和jcenter仓的聚合仓
https://maven.aliyun.com/repository/google
https://maven.aliyun.com/nexus/content/repositories/google
https://maven.google.com/
gradle-plugin
https://maven.aliyun.com/repository/gradle-plugin
https://maven.aliyun.com/nexus/content/repositories/gradle-plugin
https://plugins.gradle.org/m2/
spring
https://maven.aliyun.com/repository/spring
https://maven.aliyun.com/nexus/content/repositories/spring
http://repo.spring.io/libs-milestone/
spring-plugin
https://maven.aliyun.com/repository/spring-plugin
https://maven.aliyun.com/nexus/content/repositories/spring-plugin
http://repo.spring.io/plugins-release/
grails-core
https://maven.aliyun.com/repository/grails-core
https://maven.aliyun.com/nexus/content/repositories/grails-core
https://repo.grails.org/grails/core
apache snapshots
https://maven.aliyun.com/repository/apache-snapshots
https://maven.aliyun.com/nexus/content/repositories/apache-snapshots
https://repository.apache.org/snapshots/
<repository><id>aliyun</id><name>aliyun</name><url>http://maven.aliyun.com/nexus/content/groups/public/</url><layout>default</layout><releases><enabled>true</enabled></releases><snapshots><enabled>false</enabled></snapshots>
</repository>
在这里配置阿里云远程仓库的目的,仅为提高构件的下载速度,所以这种情况下,更推荐使用镜像。
远程仓库在哪些场景下适用呢?
- 企业内部各组开发的构件会上传至私服中,项目发生依赖时需要配置私服
- 一个开源项目,仅开源其中一部分代码。那部分未开源的代码,就可以放到企业的私有仓库中。当外部用户下载构件开源项目的时候,可指定远程仓库来下载不开源的构件
镜像配置
settings.xml
<mirror><id>alimaven</id><mirrorOf>central</mirrorOf><name>aliyun maven</name><url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
CentOS搭建Maven私服Nexus
nexus下载:Download Repository OSS
解压 nexus-3.37.3-02-unix.tar.gz
tar xvf nexus-3.37.3-02-unix.tar.gz -C ../
解压后看起来是这样的
.
├── bin
├── deploy
├── etc
├── lib
├── NOTICE.txt
├── OSS-LICENSE.txt
├── PRO-LICENSE.txt
├── public
├── replicator
└── system
修改可选配置
修改启动用户
切换目录至${NEXUS_HOME}/bin
,执行 vim nexus.rc
run_as_user=“root”
修改启动端口
切换目录至${NEXUS_HOME}/etc
,执行 vim nexus-default.properties
application-port=18081
环境变量
执行vim /etc/profile
# nexus env
export NEXUS_HOME=/soft/nexus-3.37.3-02
export PATH=$PATH:$NEXUS_HOME/bin
编辑后,执行一下source /etc/profile
启动及验证
nexus {start|stop|run|run-redirect|status|restart|force-reload}
浏览器访问:ip:18081
账户密码存放路径:/sonatype-work/nexus3/admin.password
,首次登录重新修改密码即可
Maven与Nexus整合
<repositories><repository><id>local-nexus</id><name>local-nexus</name><layout>default</layout><url>http://nna:18081/repository/maven-public/</url></repository>
</repositories>
idea pom 配置后,可能会不生效
检查一下Maven目录下的/apache-maven-3.8.1/conf/settings.xml
将pom
中配置的local-nexus
,添加到settings.xml
中,配置好后看起来像下面这样
<mirror><id>maven-default-http-blocker</id><mirrorOf>external:http:*,!local-nexus</mirrorOf><name>Pseudo repository to mirror external repositories initially using HTTP.</name><url>http://0.0.0.0/</url><blocked>true</blocked>
</mirror>
本地库批量导入Nexus
准备一个本地库
点击仓库按钮
选择maven2(hosted)
类型
将本地包上传至Nexus服务器
建立一个文件夹repo
mkdir repo
将包上传至repo
目录,上传完看起来像这样
.
├── ai
├── ant
├── antlr
├── aopalliance
├── asm
├── aspectj
├── au
├── avalon-framework
├── backport-util-concurrent
├── biz
├── bouncycastle
├── c3p0
├── cglib
├── ch
├── classworlds
├── cn
├── co
├── com
写一个上传脚本,名字为mavenimport.sh
#!/bin/bash# copy and run this script to the root of the repository directory containing files
# this script attempts to exclude uploading itself explicitly so the script name is important
# Get command line params
while getopts ":r:u:p:" opt; docase $opt inr) REPO_URL="$OPTARG";;u) USERNAME="$OPTARG";;p) PASSWORD="$OPTARG";;esac
donefind . -type f -not -path './mavenimport.sh*' -not -path '*/.*' -not -path '*/^archetype-catalog.xml*' -not -path '*/^maven-metadata-local*.xml' -not -path '*/^maven-metadata-deployment*.xml' | sed "s|^./||" | xargs -I '{}' curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} ${REPO_URL}/{} ;
赋一个执行权限:chmod a+x ./mavenimport.sh
参数注解:
-u
用户名
admin
-p
密码
123456
-r
仓库地址
http://nna:18081/repository/bihu-hosted/
完整命令:
sh mavenimport.sh -u admin -p 123456 -r http://nna:18081/repository/bihu-hosted/
耐心等待即可,在Nexus管理界面可以看到,看起来像这样
最后将我们新建立的新仓库加入到maven-public组中即可
集成开发环境IDEA Deploy至Nexus
pom 文件添加相关deploy配置
<distributionManagement><repository><id>release</id><name>Local Nexus Repository</name><url>http://nna:18081/repository/bihu-hosted/</url></repository><snapshotRepository><id>release</id><name>Local Nexus Repository</name><url>http://nna:18081/repository/bihu-hosted/</url></snapshotRepository>
</distributionManagement>
settings.xml文件找<servers>
节点,需要注意的是,pom 中的id要与server中的id一致,否则不生效,会出现401权限异常
<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>release</id><username>admin</username><password>123456</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>
7. Maven仓库相关推荐
- pom文件中引入常用的maven仓库
给大家分享几个maven仓库,如果本地总是下载很慢的话可以尝试换一下仓库或者多加几个.可以直接拖放在pom.xml中使用. 阿里云仓库 <mirrors><mirror>< ...
- 删除maven仓库中的LastUpdated文件
转自:https://www.oschina.net/code/snippet_151849_49131 maven仓库中的某个构件如果因为网络或者其他的原因,没有下载成功或者下载被中断,将会出现一个 ...
- 合并本地Maven仓库
今天遇到一个问题,就是将一个Maven项目导入到自己的开发环境Myecplise.之前的步骤都很顺利,没有问题,但是到了最后发现pom.xml文件的第一行有一个大红叉,点击错误看,是缺少jar包,但是 ...
- 国内阿里Maven仓库镜像Maven配置文件Maven仓库速度快
国内连接maven官方的仓库更新依赖库,网速一般很慢,收集一些国内快速的maven仓库镜像以备用. 最新更新:2016年11月11日 18:05:40 阿里云提供Maven私服,我把配置文件贴一下,自 ...
- 怎样在nexus 中 搜索到远程maven仓库中的jar 文件
怎样在nexus 中 搜索到远程maven仓库中的jar 文件 url: http://www.oschina.net/question/95712_21999 点击Administration菜单下 ...
- 在内网中使用maven_搭建私有maven仓库并在项目中使用
这是一篇写给女朋友看的教程...前方高能,注意避让~ 1.私有maven仓库的搭建 搭建环境为阿里云ESC服务器,CentOS.确保服务器已经安装Jdk.然后我要手把手教你安装和启动nexus. St ...
- [Android]上传到多个Maven仓库的Gradle插件RapidMavenPushPlugin
博客搬迁至https://blog.wangjiegulu.com RSS订阅:https://blog.wangjiegulu.com/feed.xml RapidMavenPushPlugin 用 ...
- 【Maven学习】Nexus私服代理其他第三方的Maven仓库
一.背景 [Maven学习]Nexus OSS私服仓库的安装和配置 http://blog.csdn.net/ouyang_peng/article/details/78793038 [Maven学习 ...
- 国内阿里Maven仓库镜像及自己收集镜像库
国内阿里Maven仓库镜像Maven配置文件Maven仓库速度快 收集的仓库如下: <?xml version="1.0" encoding="UTF-8" ...
- [maven] settings 文件 本地maven仓库
<?xml version="1.0" encoding="UTF-8"?><!-- Licensed to the Apache Softw ...
最新文章
- Android中pendingIntent的深入理解
- just have a view of the open source project i contributed!!!
- 27-----BBS论坛
- 前端学习(2802):完成资讯页面详情
- 上机环境是什么意思_Python能不能自学,可以找到什么工作?
- Java基础__Integer类型中的自动装箱
- 预言梦可能破坏质能守恒定律
- Word2vector原理
- 基于H5的实时语音聊天
- 理论计算机科学方向,计算机科学与技术专业考研方向:计算机软件与理论
- 分享下最近的Nvidia GPU 3060 laptop GPU、linzhi、Tesla算力曲线
- 人工智能的发展对生活有什么影响?
- 【关于理想】别让你的理想显得太掉价,每个人都很值钱
- 各种二极管的区别(TVS管/瞬态电压抑制二极管/稳压二极管/普通硅二极管/肖特基二极管/快恢复二极管/应用电路)
- 云台山风景区茶园骑共享单车,游玩茶园的每一个角落
- git入库基本操作流程
- Sniper模拟器的安装
- python爬虫技术如何挣钱?教你爬虫月入三万
- xiaopiu原型设计 记录
- 在线作图|在线做零模型分析(null model)