linux搭建maven私服(nexus3)
1、下载nexus3
- 官方下载: https://help.sonatype.com/repomanager3/download
- 分享: https://pan.baidu.com/s/1evfGopmF6PeXvd_tFwRnbQ 提取码:lzk0
2、安装nexus3
- cd /usr/local/
- tar -zxvf nexus-3.19.1-01-unix.tar.gz
- mv nexus-3.19.1-01-unix.tar.gz nexus
3、创建nexus用户,用root启动会提示 Detected execution as "root" user. This is NOT recommended!
- groupadd nuexs
- useradd -g nuexs nuexs
- chown -R nuexs:nuexs /usr/local/nuexs
4、启动nexus,访问localhost:8081;如果启动后访问失败,先用root用户启动一遍再换neuxs用户启动
- su nexus
- /usr/local/nexus/bin/nexus start
- curl localhost:8081
5、浏览器访问并修改登录密码,记得防火墙开放8081端口或者关闭防火墙:systemctl stop firewalld
- 查看密码:cat /usr/local/sonatype-work/nexus3/admin.password,登录账号为admin;
6、从私服上下载jar包
手动上传jar完成后,在pom.xml文件写入代码,下面的地址改为自己的仓库地址,下载成功后完事!
<repositories> <repository> <id>nexus</id> <name>Nexus Repository</name> <url>http://192.168.0.144/repository/maven-public/</url> <snapshots> <enabled>true</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </repository> </repositories> <dependencies> <dependency> <groupId>com</groupId> <artifactId>mysql-test</artifactId> <version>1.0</version> </dependency> </dependencies>
7、上传jar到私服
- 修改本地maven仓库地址.m2文件夹下的setting.xml文件,没有setting.xml文件去maven安装文件下复制一份;在<servers></servers>标签中加入
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>改成自己的密码</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>改成自己的密码</password>
</server>
- 在pom.xml中写入下面的代码,然后使用maven deploy打包项目成jar或war上传到私服仓库
- 说明:版本号带 SNAPSHOT 则会上传到snapshots仓库中
<distributionManagement> <!--pom.xml这里<id> 和 settings.xml 配置 <id> 对应 --> <repository> <id>nexus-releases</id> <name>Nexus Release Repository</name> <url>http://192.168.0.144:8081/repository/maven-releases/</url> </repository> <snapshotRepository> <id>nexus-snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://192.168.0.144:8081/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement>