Linux服务器安装Nexus构建maven私有仓库(maven私服)

一,下载nexus(linux版本)#
下载nexus(maven管理库),选择linux版本进行下载(,下载好之后也上传到/usr/local/nexus目录下。

地址:http://www.sonatype.org/nexus/go/

使用wget命令下载 wget 想要下载nexus版本的地址

wget https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.11.2-03-bundle.tar.gz

二,安装配置nexus#
解压nexus压缩包到当前文件夹

nexus-2.11.4-01-bundle.tar.gz

生成了两个目录(一个 nexus 服务,一个私有库目录)

[root@iZ2ze9ipfjhle3cz3cgb0rZ nexus]# ls
nexus-2.11.4-01 nexus-2.11.4-01-bundle.tar.gz sonatype-work

配置访问nexus端口

在nexus.properties文件中(该文件位于nexus-2.11.2-03/conf/),默认为8081端口

切换到目录:/nexus/nexus-2.11.2-03/bin/下,打开文件nexus(vim nexus)

NEXUS_HOME=”..”
改为(不修改默认也可以):
NEXUS_HOME=”nexus安装目录”
RUN_AS_USER=
改为:
RUN_AS_USER=root

切换到/usr/local/nexus/nexus-2.11.2-03/bin/目录下,启动nexus。

./nexux start

回到浏览器,访问 http://101.201.101.200:8081/nexus/,就进入到了maven管理器。
登录,默认用户名 admin 默认密码 admin123,到此安装配置结束。

三,添加jar包到maven管理器#
首先添加一个用户

给用户添加一些权限

在Respositories的3rd party中添加jar包和填写依赖信息。

注意:以后添加的第三方jar包都是上传到3rd party这个仓库的!

注意下面

添加成功!

成功之后,在左上角进行搜索,可以搜到上传的jar包信息,把右边的依赖拷贝到pom.xml文件中,该jar包就可以使用了。

这一点不要忘记,把Central仓库的Configuration配置中,Download Remote Indexes项改为true。

四,新建maven项目,进行测试#
首先在pom.xml文件中加入指定私服仓库的地址的配置。

url标签的地址/nexus/content/groups/public/就是这样子搞的!

Copy


nexus
nexus
http://101.201.101.200:8081/nexus/content/groups/public/

true


true



然后再添加刚才的jar包对应的依赖,你会发现已经下载了对应的jar包并且可以使用了。

Copy

com.test.fantongxue
ftx-test
1.0.0

写测试方法进行测试,TestUtil工具类是可以使用的。

Copy
public static void main(String[] args) {
TestUtil testUtil=new TestUtil();
Integer add = testUtil.add(1, 2);
System.out.println(add);
}
效果如下图

五,maven私服仓库的扩展#
下面是对maven私服仓库的扩展!

项目使用nexus私服的插件,在项目的pom.xml文件中指定插件仓库

Copy


nexus
nexus
http://192.168.1.103:8081/nexus/content/groups/public/

true


true



如果想本机所有的maven项目都使用私服的组件,可以在maven的设置文件settings.xml中添加属性,并激活

Copy


nexusProfile


nexus
nexus
http://192.168.1.103:8081/nexus/content/groups/public/

true


true




nexusProfile 项目发布到私服,maven项目使用命令:mvn clean deploy;需要在pom文件中配置一下代码;

Copy


user-release
User Project Release
http://192.168.1.103:8081/nexus/content/repositories/releases/


user-snapshots
User Project SNAPSHOTS
http://192.168.1.103:8081/nexus/content/repositories/snapshots/


了解maven全局配置文件settings.xml可以参考这篇帖子!


Linux服务器安装Nexus构建maven私有仓库(maven私服)
https://blog.jeecloud.cn/2020/07/21/20200722021418/
作者
pshgao
发布于
2020年7月22日
许可协议