maven 使用nexus 搭建私服
2016-11-08 21:16
363 查看
1 . 私服简介
私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件。有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库;否则,私服请求外部的远程仓库,将构件下载到私服,再提供给本地仓库下载。
我们可以使用专门的 Maven 仓库管理软件来搭建私服,比如:Apache Archiva,Artifactory,Sonatype
Nexus。这里我们使用 Sonatype Nexus。
2 . 安装Nexus
2 . 1 . 下载Nexus
Nexus 专业版是需要付费的,这里我们下载开源版 Nexus OSS。Nexus 2.x 提供两种安装包,一种是包含 Jetty 容器的 bundle 包,另一种是不包含容器的 war 包。下载地址:http://www.sonatype.org/nexus/go。
2 . 2 . 使用安装包安装Nexus
解压nexus-3.1.0-04-win64.zip,
得到以下目录
1.nexus-3.1.0-04 nexus程序
2.sonatype-work nexus工作目录
(数据,备份nexus的时候可以备份这个文件夹)
nexus默认端口是8081
可以在nexus-3.1.0-04\etc\nexus-default.properties修改
,打开命令提示符,进入nexus-3.1.0-04\bin目录,键入nexus命令(为方便启动和退出Nexus,可将bin目录添加到环境变量):
常用命令
1.nexus.exe
/install 安装nexus为系统服务
2.nexus.exe
/uninstall 卸载nexus为系统服务
3.nexus.exe
/start 启动nexus服务
4.nexus.exe
/stop 停止nexus服务
执行 nexus install 将Nexus安装为Windows服务。可将服务启动方式设为手动,以后通过 nexus start 即可启动Nexus ,通过 nexus stop 退出Nexus:
打开浏览器,访问:http://localhost:8081/:
新版没用了项目名/nexus
默认登录: admin/admin123
登录之后才可以配置nexus私服
Nexus 的仓库分为这么几类:
hosted 宿主仓库:主要用于部署无法从公共仓库获取的构件(如 oracle 的 JDBC 驱动)以及自己或第三方的项目构件;
proxy 代理仓库:代理公共的远程仓库;
virtual 虚拟仓库:用于适配 Maven 1;
group 仓库组:Nexus 通过仓库组的概念统一管理多个仓库,这样我们在项目中直接请求仓库组即可请求到仓库组管理的多个仓库。
配置按钮配置仓库、用户、权限等。
3 . 配置Maven使用私服
私服搭建成功,我们就可以配置 Maven 使用私服,以后下载构件、部署构件,都通过私服来管理。
在 settings.xml 文件中,为所有仓库配置一个镜像仓库,镜像仓库的地址即私服的地址(这儿我们使用私服公共仓库组 Public Repositories 的地址):
1. 先在maven目录/conf/setting.xml的servers添加配置:
2
3
4
5
工程中配置,发布/私服工厂
私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件。有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库;否则,私服请求外部的远程仓库,将构件下载到私服,再提供给本地仓库下载。
我们可以使用专门的 Maven 仓库管理软件来搭建私服,比如:Apache Archiva,Artifactory,Sonatype
Nexus。这里我们使用 Sonatype Nexus。
2 . 安装Nexus
2 . 1 . 下载Nexus
Nexus 专业版是需要付费的,这里我们下载开源版 Nexus OSS。Nexus 2.x 提供两种安装包,一种是包含 Jetty 容器的 bundle 包,另一种是不包含容器的 war 包。下载地址:http://www.sonatype.org/nexus/go。
2 . 2 . 使用安装包安装Nexus
解压nexus-3.1.0-04-win64.zip,
得到以下目录
1.nexus-3.1.0-04 nexus程序
2.sonatype-work nexus工作目录
(数据,备份nexus的时候可以备份这个文件夹)
nexus默认端口是8081
可以在nexus-3.1.0-04\etc\nexus-default.properties修改
,打开命令提示符,进入nexus-3.1.0-04\bin目录,键入nexus命令(为方便启动和退出Nexus,可将bin目录添加到环境变量):
常用命令
1.nexus.exe
/install 安装nexus为系统服务
2.nexus.exe
/uninstall 卸载nexus为系统服务
3.nexus.exe
/start 启动nexus服务
4.nexus.exe
/stop 停止nexus服务
执行 nexus install 将Nexus安装为Windows服务。可将服务启动方式设为手动,以后通过 nexus start 即可启动Nexus ,通过 nexus stop 退出Nexus:
打开浏览器,访问:http://localhost:8081/:
新版没用了项目名/nexus
默认登录: admin/admin123
登录之后才可以配置nexus私服
Nexus 的仓库分为这么几类:
hosted 宿主仓库:主要用于部署无法从公共仓库获取的构件(如 oracle 的 JDBC 驱动)以及自己或第三方的项目构件;
proxy 代理仓库:代理公共的远程仓库;
virtual 虚拟仓库:用于适配 Maven 1;
group 仓库组:Nexus 通过仓库组的概念统一管理多个仓库,这样我们在项目中直接请求仓库组即可请求到仓库组管理的多个仓库。
配置按钮配置仓库、用户、权限等。
3 . 配置Maven使用私服
私服搭建成功,我们就可以配置 Maven 使用私服,以后下载构件、部署构件,都通过私服来管理。
在 settings.xml 文件中,为所有仓库配置一个镜像仓库,镜像仓库的地址即私服的地址(这儿我们使用私服公共仓库组 Public Repositories 的地址):
<mirrors> <mirror> <id>central</id> <mirrorOf>*</mirrorOf> <!-- * 表示让所有仓库使用该镜像--> <name>central-mirror</name> <url>http://localhost:8081/repository/maven-public//</url> </mirror> </mirrors>
maven以及配置使用
1. 先在maven目录/conf/setting.xml的servers添加配置:<server> <id>nexus</id> <username>admin</username> <password>admin123</password> </server>1
2
3
4
5
工程中配置,发布/私服工厂
<!-- 配置私服工厂 --> <repositories> <repository> <id>nexus</id> <url>http://ip:8081/repository/maven-public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <url>http://ip:8081/repository/maven-public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> <!-- 配置发布到私服 --> <distributionManagement> <repository> <id>nexus</id> <name>Nexus Release Repository</name> <url>http://ip:8081/repository/maven-releases/</url> </repository> <snapshotRepository> <id>nexus</id> <name>Nexus Snapshot Repository</name> <url>http://ip:8081/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement>
相关文章推荐
- 使用nexus搭建maven私服、手动更新索引
- 使用Nexus搭建Maven私服
- 使用Nexus搭建Maven私服
- 不错的maven学习笔记,收藏——Maven学习 (四) 使用Nexus搭建Maven私服
- 使用Nexus搭建Maven私服
- 使用Nexus搭建Maven私服
- 使用Nexus搭建Maven私服
- 使用Sonatype Nexus搭建Maven私服后如何添加第三方JAR包?
- Maven学习 (四) 使用Nexus搭建Maven私服
- 搭建配置私服-nexus ,Maven中的使用——3
- Maven学习 (四) 使用Nexus搭建Maven私服
- Maven学习:使用Nexus搭建Maven私服
- Maven学习 (四) 使用Nexus搭建Maven私服
- Maven学习 (四) 使用Nexus搭建Maven私服
- 在操作系统Centos 6.3 上使用Nexus 2.8搭建MAVEN私服 及 cloudstack 开发环境
- Maven学习 (四) 使用Nexus搭建Maven私服
- 使用nexus搭建maven私服、手动更新索引
- maven--私服的搭建(Nexus的使用)
- 使用nexus为maven搭建私服
- maven--私服的搭建(Nexus的使用)