Nexus 是一个强大的 Maven 仓库管理器, 它极大地简化了自己内部仓库的维护和外部仓库的访问.
二, 安装 Nexus
1. 解压 nexus 文件
[root@centos6 var]# tar -zvxf nexus-2.12.0-01-bundle.tar.gz
注: 解压后有两个文件夹:
nexus-2.12.0-01: 是 nexus 的核心文件
sonatype-work :maven 下载 jar 存放地址
2. 启动 Nexus
- [root@centos6 nexus-2.12.0-01]# ./bin/nexus start
- - ****************************************
- WARNING - NOT RECOMMENDED TO RUN AS ROOT
- ****************************************
- If you insist running as root, then set the environment variable RUN_AS_USER=root before running this script.
默认情况下, 不建议以 root 用户运行 Nexus, 可以修改 bin/nexus 中的配置跳过警告 (修改 RUN_AS_USER=root)
[root@centos6 nexus-2.12.0-01]# vi bin/nexus
重新启动 Nexus
- [root@centos6 nexus-2.12.0-01]# ./bin/nexus start
- - ****************************************
- WARNING - NOT RECOMMENDED TO RUN AS ROOT
- ****************************************
- Starting Nexus OSS...
- Started Nexus OSS.
注: Nexus 默认端口 8081, 如果想修改端口. 修改 / conf/nexus.properties 文件
访问网址: http://192.168.1.11:8081/nexus/#welcome
点击右上角的 Log In 按钮即可登陆了. 默认登录账号 / 密码为: admin/admin123 , 登陆成功后的界面
点击 Repositories, 将列表中所有 Type 为 proxy 的项目的 Configuration 中的 Download Remote Indexes 设置为 True
将 Releases 仓库的 Deployment Policy 设置为 Allow ReDeploy
当然我们也避免不了会使用到一些第三方的 jar , 而这些 jar 包也不存在于互联网上的 maven 中央仓库中, 这时我们可以手工添加 jar 到我们的私服中.
添加第三方 jar 如下:
填写完必选字段, 点击 Upload Artifact(s) 按钮即可.
3. 配置本地项目引用私服
自动发布构件到远程仓库, 在工程 pom.xml 中添加
- releases
- http://192.168.1.11:8081/nexus/content/repositories/releases
- snapshots
- http://192.168.1.11:8081/nexus/content/repositories/snapshots
修改本地 $MAVEN_HOME\conf 目录下的 settings.xml 配置文件, 添加如下配置
- releases
- admin
- admin123
- snapshots
- admin
- admin123
在本地工程目录下执行:
mvn deploy
所部署的包就自动上传到了 nexus 安装目录下的
4. 配置 Maven 从 Nexus 下载构件
在 POM 中配置 Nexus 私服, 这样的配置只对当前的 Maven 项目有效.
- public
- Team Maven Repository
- http://192.168.1.11:8081/nexus/content/groups/public/
- true
- true
- public
- Team Maven Repository
- http://192.168.1.11:8081/nexus/content/groups/public/
- true
- true
在 settings.xml 中配置 profile 元素, 这样就能让本机所有的 Maven 项目都使用自己的 Maven 私服.
- public
- Team Maven Repository
- http://192.168.1.11:8081/nexus/content/groups/public/
- true
- default
- true
来源: http://www.bubuko.com/infodetail-2964249.html