一、安装 NEXUS REPOSITORY MANAGER 3
- 下载
到官网下载nexus(这里使用 3.17.0-01 版本)
官网:https://my.sonatype.com/

选择自己系统对应的文件(这里选择Windows系统)

- 解压
将压缩包解压到一个文件夹下

- 安装
用管理员方式打开命令行窗口,进入解压到的文件夹下的nexus-3.17.0-01/bin
执行命令:nexus.exe/install
安装成功后,nexus是一个服务,打开服务可以看到nexus。

- 启动nexus服务
执行命令:
或在服务里 右键/启动nexus.exe/start

- 默认的配置文件
在D:\自己的文件夹\nexus-3.17.0-01\etc\nexus-default.properties

- 访问 localhost:8081

- 登录
nexus有默认的用户名和密码
用户名:admin
密码:注意:网上绝大多数会说密码是 admin123,但是在这里是登不进去的。
实际的密码在解压后的 sonatype-work\nexus3 下的 admin.password 文件中。
复制文件中的密码然后登录。登录成功后,会叫你修改密码。

到这一步,NEXUS REPOSITORY MANAGER 3 就安装完成了。
二、仓库类型说明
先看看仓库:

- 宿主仓库(hosted)
用来存放 公司开发的jar包,有测试版本(maven-snapshots)、发行版本(maven-releases)、第三方jar包等。 - 代理仓库(proxy)
用来代理中央仓库、Apache下测试版本的jar包。 - 组仓库(group)
包含了宿主仓库,代理仓库。将来连接组仓库就可以下载jar包了。
三、上传jar包到私服
将自己的项目打包发布到私服,可以让别人从私服上下载jar包。
步骤:
- 配置maven的setting.xml文件
用来认证登录,指定仓库地址。
在setting.xml文件中添加:<servers> <server> <id>releases</id> <username>admin</username> <password>tiger</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>tiger</password> </server> </servers>
- 配置要上传到私服的项目的pom.xml文件
用来指定私服的仓库地址
在pom.xml文件添加<distributionManagement> <repository> <id>releases</id> <url>http://localhost:8081/repository/maven-releases/</url> </repository> <snapshotRepository> <id>snapshots</id> <url>http://localhost:8081/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement>
私服地址怎么来的?

- 将项目打包发布到私服
进入项目根目录,执行命令
根据maven的生命周期,会执行:compile–>test–>package–>install–>deploy。mvn deploy

- 最后就是检查是否部署成功


如上图,则部署成功。
四、下载私服上的jar包
- 配置模板
在setting.xml文件中添加:<profiles> <profile> <!-- profile的id --> <id>dev</id> <repositories> <repository> <!-- 仓库id,repositories可以配置多个仓库,保证id不重复 --> <id>nexus</id> <!-- 仓库地址,即nexus仓库组的地址 --> <url>http://localhost:8081/repository/maven-public/</url> <!-- 是否下载releases构件 --> <releases> <enabled>true</enabled> </releases> <!-- 是否下载snapshots构件 --> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <!-- 插件仓库,maven的运行依赖插件,也需要从私服下载插件 --> <pluginRepository> <id>public</id> <name>Public Repositories</name> <url>http://localhost:8081/repository/maven-public/</url> </pluginRepository> </pluginRepositories> </profile> </profiles> - 激活模板
在setting.xml文件中添加:<activeProfiles> <!-- 激活dev模板 --> <activeProfile>dev</activeProfile> </activeProfiles> - 在某个maven工程中添加依赖
在pom.xml文件中添加<dependencies> <dependency> <groupId>com.seven</groupId> <artifactId>maven_springboot_obj</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> </dependencies> - 查看是否导入成功

更新时间:2020-1-9
本文详细介绍了Nexus Repository Manager 3的安装步骤,包括下载、解压、安装及服务启动过程。同时,深入讲解了仓库类型及其功能,如宿主仓库、代理仓库和组仓库。此外,还提供了如何上传和下载jar包的具体操作,以及在Maven项目中配置私服的方法。
2418

被折叠的 条评论
为什么被折叠?



