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/
就是这样子搞的!
<repositories>
<repository>
<id>nexus</id>
<name>nexus</name>
<url>http://101.201.101.200:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
如果没有效果,或者下载的没有jar包,只有两个.lastUpload文件等情况,可以换成下面的方式试一下,估计就可以了
<repositories>
<repository>
<id>maven-ossez</id>
<name>OSSEZ Repository</name>
<url>http://101.201.101.200:8081/nexus/content/groups/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven-ossez</id>
<name>OSSEZ Repository</name>
<url>http://101.201.101.200:8081/nexus/content/groups/public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
然后再添加刚才的jar
包对应的依赖,你会发现已经下载了对应的jar
包并且可以使用了。(settings.xml配置文件还使用阿里云镜像即可,不需要更改settings.xml的配置)
<dependency>
<groupId>com.test.fantongxue</groupId>
<artifactId>ftx-test</artifactId>
<version>1.0.0</version>
</dependency>
写测试方法进行测试,TestUtil
工具类是可以使用的。
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文件中指定插件仓库
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>nexus</name>
<url>http://192.168.1.103:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
如果想本机所有的maven项目都使用私服的组件,可以在maven的设置文件settings.xml中添加属性,并激活
<profiles>
<profile>
<id>nexusProfile</id>
<repositories>
<repository>
<id>nexus</id>
<name>nexus</name>
<url>http://192.168.1.103:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<!-- 激活 -->
<activeProfiles>
<activeProfile>nexusProfile</activeProfile>
</activeProfiles>
项目发布到私服,maven项目使用命令:mvn clean deploy;需要在pom文件中配置一下代码;
<distributionManagement>
<repository>
<id>user-release</id>
<name>User Project Release</name>
<url>http://192.168.1.103:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>user-snapshots</id>
<name>User Project SNAPSHOTS</name>
<url>http://192.168.1.103:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
-------------------------------------------
个性签名:独学而无友,则孤陋而寡闻。做一个灵魂有趣的人!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!
万水千山总是情,打赏一分行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主,哈哈哈(っ•̀ω•́)っ✎⁾⁾!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)