第一步.下载安装nexus
在这里我使用的版本是nexus-3.6.2-01-mac.tgz,因为3.x的界面以及实现比较简单下面直接开始
1.首先进行解压缩到/usr/local目录下
tar -zxvf nexus-3.6.2-01-mac.tgz -C /usr/local/
2.配置全局环境变量,进入到/etc/profile
export NEXUS_HOME=/usr/local/nexus-3.6.2-01
export PATH=${NEXUS_HOME}/bin:$PATH
export RUN_AS_USER=root //为了以后打算
3.然后进入到bin目录下启动:
./nexus start
查看进程是否启动成功:
ps -aux | grep nexus
显示如下表示成功:
第二步.进入到私服的UI界面进行操作
1.在浏览器上输入ip:8081/nexus,出现以下界面表示真正的安装成功!
2.点击右上角的Sign in 进行登录,默认的用户名admin,密码admin123,登陆之后开始创建自己的仓库
3.点击create repository之后填写其中的信息进行创建即可,但是要选择maven2的仓库进行创建,具体指代的意思一会解释。
解释:
proxy:
远程仓库的代理,比如说nexus配置了一个central repository的proxy,当用户向这个proxy请求一个artifact的时候,会现在本地查找,如果找不到,则会从远程仓库下载,然后返回给用户。
hosted:
宿主仓库,用户可以把自己的一些仓库deploy到这个仓库中
group:
仓库组,是nexus特有的概念,目的是将多个仓库整合,对用户暴露统一的地址,这样就不需要配置多个仓库地址。
所以我们的项目是要发布到本地的Nexus私服,自然就要选择hosted。
4.具体信息按照下图中圈中的配置,仓库就创建成功了:
5.创建User:
然后填写用户的信息:
填写完成用户就创建成功了。
第三步.手动上传jar到私服中
1.首先在自己本地的maven的setting文件中加上以下配置,就是创建的用户的名字和密码:
<server>
<id>ligh</id>
<username>ligh</username>
<password>liguohui</password>
</server>
2.本地打包完成之后的jar,上传到私服中:
mvn deploy:deploy-file -DgroupId=cc.huluwa.electronic.contract.sdk.core -DartifactId=electronic-contract-sdk-core -Dversion=v1.0.0 -Dpackaging=jar -Dfile=/Users/fish/sdk-core/electronic-contract-sdk-core/target/sdk-core.jar -Durl=http://ip:8081/repository/ligh/ -DrepositoryId=ligh
注意:
groupId: 是你项目中的groupId
artifactId:是你项目中的artifactId
-Dfile:指代的是本地jar包的路径
Durl: 是私服仓库的地址
3.执行完成之后就可以在私服仓库中进行查看是否上传成功!
4.如果想要在其他项目中调用,需要在下面加上以下配置,既可以在pom文件中引入
<repositories>
<repository>
<id>ligh</id>
<name>Nexus Repository</name>
<url>http://ip:8081/repository/ligh/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>ligh</id>
<name>Nexus Plugin Repository</name>
<url>http://ip:8081/repository/ligh/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
如果引入没有问题就表示成功!