部署环境:
系统版本:Mac os 12.0.1
Nexus版本:3.37.3
1.下载Nexus安装包下载地址
跟据自己的设备下载合适的安装包版本
Unix archive:linux
Windows archive:windows
OSX archive:mac os
2.启动Nexus
找到安装包路径
你的文件目录/nexus-3.37.3-02/bin
打开cmd进入到安装包下的bin目录启动你的nexus
看到如下字样,则表启动成功
3.访问Nexus
不知道你的nexus访问地址?没关系,我教你。
你的文件目录/nexus-3.37.3-02/etc/nexus-default.properties
在这里是你的nexus配置文件
打开配置文件
application-port=访问Nexus端口号(默认8081)
application-host=访问Nexus的ip地址(默认localhost本地ip)
所以你的访问路径就是 http://localhost:8081
看到如下图则表示启动成功
4.登录Nexus
到这里肯定有人会问,我不知道账号密码,怎么办。
很多文章会告诉你,账号是admin,密码是admin123
但是,那是旧版本的Nexus,账号依然是admin,新版本的密码可不是,别瞎说。
你的文件目录/nexus-3.37.3-02/etc/sonatype-work/nexus3/admin.password
提示:我这里已经修改过了密码,所以admin.password就消失了
打开文件,直接复制密码登录即可,登录成功之后会让你再输入一次密码,这是修改密码的步骤,以后将用这个密码登录Nexus。
5.打包Jar上传到Nexus
1)全局配置Nexus
找到maven安装目录
文件路径/maven/版本号/libexec/conf/settings.xml
2)servers节点
<server><!-- 发布版本-->
<id>nexus</id> <!-- 随意填写,但项目中repository的id得与这里一致-->
<username>admin</username> <!-- 账户-->
<password>admin123</password> <!-- 密码-->
</server>
<server><!-- 发布版本-->
<id>nexus-releases</id> <!-- 随意填写,但项目中repository的id得与这里一致-->
<username>admin</username> <!-- 账户-->
<password>admin123</password> <!-- 密码-->
</server>
<server><!-- 发布版本-->
<id>nexus-snapshots</id> <!-- 随意填写,但项目中repository的id得与这里一致-->
<username>admin</username> <!-- 账户-->
<password>admin123</password> <!-- 密码-->
</server>
3)mirrors节点
<mirror>
<id>nexus</id>
<!--表示访问哪些工厂时需要使用镜像-->
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/repository/maven-public/</url>
</mirror>
6.打包上传Jar
这里以vscode为例子,其他开发工具大同小异
1)pom.xml配置你的Nexus仓库地址信息
<!-- 本地nexus私有库-->
<distributionManagement>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>http://localhost:80801/repository/maven-snapshots/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</snapshotRepository>
<repository>
<id>nexus-releases</id>
<url>http://localhost:80801/repository/maven-releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</distributionManagement>
2)在终端cmd输入mvn clean
3)在终端cmd输入mvn deploy
看到BUILD SUCCESS字样则代表上传成功。
回到Nexus查看上传的jar
在这里即可以看到刚才上传的jar文件(别纠结我的为什么那么多个,因为我之前就上传了好几个)
7.引用Nexus库jar
找到maven安装目录
文件路径/maven/版本号/libexec/conf/settings.xml
1)profiles节点
<profile>
<!--profile 的 id-->
<id>nexus</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 不允许重复,如果重复后边配置会覆盖前边 -->
<id>public</id>
<name>Public Repositories</name>
<url>http://localhost:8081/repository/maven-public/</url>
<!--是否下载 releases 构件-->
<releases>
<enabled>true</enabled>
</releases>
<!--是否下载 snapshots 构件-->
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
2)activeProfiles节点
激活配置
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
到这里,你的项目已经可以正常使用Nexus了。
end