一、nexus下载安装搭建私服
1、下载
下载官网
https://www.sonatype.com/download-oss-sonatype 或百度搜索nexus
下载最新版本
下载2.x版本
选择需要的版本,有最新也后旧版本
下载误区:
2、安装及配置
下载完毕之后减压到指定位置:
在D:\nexus\nexus-2.14.13-01\bin\jsw目录下载选择自己的操作系统版本(我的是window 64位的)
安装并启动:
首先点击安装,在启动服务,
3、启动时报错
若启动失败,打开服务,从服务中启动时报1067:进程外终止,原因是jdk未生效。
进入nexus安装目录,修改bin\jsw\conf\wrapper.conf中的wrapper.java.command,重新启动即可
4、修改端口号
进入nexus目录下修改nexus.properties中修改
我的修改为了8090,默认为8081
4、访问nexus
打开浏览器,输入localhost:8090/nexus回车即可
5、登录私服
点击右上角的Log In进行登录
nexus的默认登录账号为:admin,密码为:admin123
到这里,私服的安装就是完成了。
2、整合maven到私服
1、配置maven
配置本地仓库
<localRepository>E:\Maven3.6\.m2</localRepository>
配置jdk:
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
2、配置私服
配置私服镜像,使用的发布版和快照版镜像,不使用maven中央仓库以及阿里云仓库
<mirror>
<id>nexus-releases</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8091/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>nexus-snapshots</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8091/nexus/content/repositories/apache-snapshots/</url>
</mirror>
配置私服构建(连接私服用的到 jar 等内容)
<profile>
<id>nexusTest</id>
<repositories>
<repository>
<id>local-nexus</id>
<url>http://127.0.0.1:8091/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
配置让私服构建生效
<activeProfiles>
<!--激活 id 为 nexusTest 的 profile-->
<activeProfile>nexusTest</activeProfile>
</activeProfiles>
3、测试
创建一个maven项目,(jar包类型即可),在pom文件中添加一个maven本地仓库中没有的jar的依赖
保存后查看控制台jar下载来源是否为私服。
到这里及整合完成了。
三、上传项目到私服
1、在pom文件中配置私服路径
路径依然为发布版和快照版
<distributionManagement>
<repository>
<id>releases</id>
<url>http://localhost:8091/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://localhost:8091/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
2、在 settings.xml 中配置连接私服仓库的用户名和密码
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
然后启动项目 右键项目–> run as 输入 deploy
这样发布的项目有快照和非快照的两个版本。
至于快照与非快照项目的区别我这里就不在解释了。