Sonatype Nexus 搭建maven私服
来源:互联网 发布:淘宝教育可以下载吗 编辑:程序博客网 时间:2024/06/05 18:21
系统版本:ubuntu-14.04.4-server 64-bit
maven版本:apache-maven-3.3.9
java版本:1.7.0_121 64-bit
搭建maven私服之前需要了解的几个名词
Proxy Repository 代理仓库
A Proxy Repository is a proxy of a remote repository. By default, Nexus Repository Manager ships with the following configured proxy repositories
Apache Snapshots/Codehaus Snapshots/Central
代理仓库就是远程仓库的代理。默认Nexus仓库管理自带三种代理仓库
Apache Snapshots/Codehaus Snapshots/Central
Hosted Repository 宿主仓库
A Hosted Repository is a repository that is hosted by the repository manager. Nexus Repository Manager ships with the following configured hosted repositories
3rd Party/Releases/Snapshots
宿主仓库就是被仓库管理者持有的仓库,Nexus仓库管理自带三种宿主仓库
3rd Party/Releases/Snapshots
Virtual Repository 虚拟仓库(基本没用过)
A Virtual Repository serves as an adaptor to and from different types of repositories
虚拟仓库作为一个适配器来对不同类型的仓库进行转换(例如maven 1/ 2之间转换)
Repository Group 仓库组
看名字就知道,一些其它仓库的组合,不具有实际仓库的功能,只是对现有的仓库组织起来,客户端请求的还是实际配置的仓库
SNAPSHOT(快照版本)
在maven中SNAPSHOT版本代表正式发布(release)的版本之前的开发版本,在pom中用x.y-SNAPSHOT表示
RELEASE(发布版本,稳定版本)
在maven中RELEASE代表着稳定的版本,unchange,不可改变的,在maven中SNAPSHOT与RELEASE版本在策略上是完全不同的方式,SNAPSHOT会根据你的配置不同,频繁的从远程仓库更新到本地仓库;而RELEASE则只会在第一次下载到本地仓库,以后则会先直接从本地仓库中寻找
下载Nexus Repository OSS开源版本
下载地址
https://www.sonatype.com/download-oss-sonatype
文档
http://books.sonatype.com/nexus-book/reference/index.html
下载方式
可以先下载好,然后拷贝过去,或者在服务器上使用wget直接下载
wget https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.14.1-01-bundle.tar.gz
解压缩文件
tar xvzf nexus-2.14.1-01-bundle.tar.gz
进入nexus-2.14.1-01/bin目录,启动 $: ./nexus start
启动成功
Starting Nexus OSS…
Started Nexus OSS.
配置文件位置为nexus-2.14.1-01/conf/nexus.properties,默认端口8081,webapp为nexus,日志文件nexus-2.14.1-01/logs/wrapper.log
启动之后,可以通过tail -f logs/wrapper.log 在终端事实监视日志输出
工作目录为sonatype-work
nexus-2.14.1-01/bin/jsw/conf/wrapper.conf 为Jetty servlet容器启动的核心配置文件,可以对java内存配置、java虚拟机参数配置、log日志文件配置等
进入系统 http://192.168.1.84:8081/nexus,如图
工作目录为sonatype-work
开启代理仓库的Download Remote Indexes,直接维护远程仓库索引,来达到快速搜索组件
比较常用的几个公共仓库地址:
http://repo1.maven.org/maven2/
http://central.maven.org/maven2/
http://repository.jboss.org/nexus/content/groups/public/
本来以为aliyun也是仓库内,但是试了一下,发现应该就是镜像,access forbidden请求拒绝
http://maven.aliyun.com/nexus/content/groups/public/
添加代理仓库
这里以添加ibiblio Repository为例http://maven.ibiblio.org/maven2/
把ibiblio Repository添加到仓库组
默认,nexus会给你创建一个仓库组,现在就把他添加到这个默认的仓库组里
- 注意顺序,这里的顺序会影响到你搜索组件的顺序,默认搜索组件的顺序是releases(本机发布版)>snapshots(本机快照)>3rd part(本机下载的第三方插件)>central(远程代理中央仓库)> ibiblio(远程ibiblio代理仓库,在国内速度还是比较快的,可以放到中央仓库的前面)
注:可以从Routing中查看代理仓库的状态
添加第三方组件(oracle)
可以看到在仓库中已经存在,并且在仓库组中也可以看到,同时,也能在索引中找到
查看你的工作目录,可以看到oracle的jdbc驱动已经下载到仓库本地
使用私服地址配置本地仓库
两种方式,一是在maven的配置文件中全局配置;二是在所在的项目pom文件中配置,只针对本项目的
一、 全局配置
这里采用覆盖默认的central仓库的方式,即所有的组件都通过我们自己的nexus私服下载,修改maven配置文件settings.xml
<mirrors> <mirror> <id>nexus</id> <mirrorOf>*</mirrorOf> <url>http://192.168.1.86:8081/nexus/content/groups/public/</url> </mirror></mirrors><profiles> <profile> <id>nexus</id> <repositories> <repository> <id>central</id> <url>http://any-site.unimportant</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://any-site.unimportant</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile></profiles><activeProfiles> <activeProfile>nexus</activeProfile></activeProfiles>
二、pom文件配置
<repositories> <repository> <id>nexus</id> <url>http://192.168.1.86:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository></repositories><pluginRepositories> <pluginRepository> <id>nexus</id> <url>http://192.168.1.86:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository></pluginRepositories>
这时我们在dependency中加入
<dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.3.2</version></dependency>
更新maven依赖,会发现仓库中下载了common-fileupload的组件
发布组件到私服仓库
首先你需要nexus发布组件的权限的用户名/密码
修改maven配置文件settings.xml
<servers> <server> <id>deploymentRepo</id> <username>admin</username> <password>admin123</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>
同时在pom文件中增加如下分发配置,发布到私服下的snapshots下面,注意id必须与settings.xml中一致
<distributionManagement> <repository> <id>deploymentRepo</id> <name>ProjectSnapshots</name> <url>http://192.168.1.86:8081/nexus/content/repositories/snapshots/</url> </repository></distributionManagement>
我的测试项目pom如下
在终端执行
mvn deploy -Dmaven.test.skip=true
在nexus上可以看到
成功分发到私服!
- Sonatype Nexus 搭建Maven 私服
- Sonatype Nexus 搭建Maven 私服
- Sonatype Nexus 搭建Maven 私服
- Sonatype Nexus 搭建Maven 私服
- Sonatype Nexus 搭建Maven 私服
- Sonatype Nexus 搭建Maven 私服
- Sonatype Nexus 搭建Maven 私服
- Sonatype Nexus 搭建Maven 私服
- Sonatype Nexus 搭建Maven 私服
- Sonatype Nexus 搭建Maven 私服
- Sonatype Nexus 搭建Maven 私服
- Sonatype Nexus 搭建Maven 私服
- Sonatype Nexus 搭建Maven 私服
- Sonatype Nexus 搭建Maven 私服
- Sonatype Nexus 搭建Maven 私服
- Sonatype Nexus 搭建Maven 私服
- Sonatype Nexus 搭建Maven 私服
- Sonatype Nexus 搭建Maven 私服
- [POJ1740]A New Stone Game(博弈)
- 自己使用的.vimrc配置
- Spring Cloud构建微服务架构(六)高可用服务注册中心
- java.util.List 中有一个 subList() 方法使用小结
- 更新 将B表的数据更新到A表中的某个字段的sql(根据条件)
- Sonatype Nexus 搭建maven私服
- GDAL中的进度条
- php关于经纬度的计算处理
- 第38篇 前端找老师代码放置及php对上传文件限制及SVN上传与下载
- git获取linux内核源码及分支管理
- 可以在function里面直接调用KindEditor对象而不用KindEditor.ready(function(K)这样去拿
- 反向传导算法
- 验证非空和数字
- 创建内存测试进程