服务器搭建nexus3.0,上传第三方jar包,项目依赖jar包
下载nexus
官网下载地址:www.sonatype.com/download-oss-sonatype
选择Unix版本下载
- 官网下载不了也可以在此地址下载 http://119.29.241.56:8080/view/1320(网上找的)
- 下载成功后放置到服务器opt/nexus文件夹下
- 解压命令
tar -zxvf nexus-3.13.0-01-unix.tar.gz
- cd 到其bin目录下,不建议使用root用户启动nexus,若想使用则将bin目录下nexus里run_as_user=’'修改为run_as_user=root
- 在bin目录下使用./nexus start 启动nexus ,启动效果如下
- 可使用./nexus status 查看启动状态
- 浏览器访问http://服务器地址:8081(nexus默认端口号是8081,服务器安全组开放8081端口),出现
- 使用nexus默认用户名:admin,密码:admin123 登录
- 创建3rdParty的存储库
Repository的type属性有:proxy,hosted,group三种
proxy:即你可以设置代理,设置了代理之后,在你的nexus中找不到的依赖就会去配置的代理的地址中找。
hosted:你可以上传你自己的项目到这里面。
group:它可以包含前面两个,是一个聚合体。一般用来给客户一个访问nexus的统一地址。
- 在此选择maven2(hosted)
- 打开本地maven的setting文件,加入
<server>
<id>3rdParty</id>
<username>admin</username>
<password>admin123</password>
</server>
- 在项目的pom.xml里面添加
<distributionManagement>
<repository>
<id>3rdParty</id>
<name>3rdParty Repository</name>
<url>http://服务器IP:8081/repository/3rdParty/</url>
</repository>
</distributionManagement>
- 点击maven发布
- 发布成功nexus就有了
依赖测试
- 在要依赖jar包项目的pom文件加入
<repositories>
<repository>
<id>public</id>
<name>public Repository</name>
<url>http://服务器IP:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
</repository>
</repositories>
<dependency>
<artifactId>maven模块名</artifactId>
<groupId>maven组id</groupId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
- 可以看到maven中已经有该jar包