Linux搭建maven私服
1.下载nexus
地址:https://www.sonatype.com/download-sonatype-trial?submissionGuid=f15e6fa2-fdd0-4d15-9aae-93fd99396cde,这里我下载的是nexus-2.14.8-01-bundle.tar.gz。
2.linux服务器上创建目录/dev/nexus,将下载好的nexus-2.14.8-01-bundle.tar.gz上传到该目录下,tar -zxvf nexus-2.14.8-01-bundle.tar.gz 解压。解压后有两个目录:
注:解压后有两个文件夹:nexus-2.12.0-01: 是nexus的核心文件
sonatype-work :maven下载jar存放地址
/dev/nexus/nexus-2.14.8-01/conf目录下的nexus.properties配置文件存放端口等的配置信息。3.cd /dev/nexus/nexus-2.14.8-01/bin,vim nexus,找到 这一行:#RUN_AS_USER= ,修改为:RUN_AS_USER=root
4.启动nexus服务:./nexus start
注意防火墙的设置,开放8081端口。
5.访问: http://ip:8081/nexus,出现如下页面则nexus部署正常:
6.nexus配置
点击右上角登录,默认用户名,密码:admin/admin123
登陆成功后,点击Repositories,将列表中所有Central的 Configuration 中的 Download Remote Indexes 设置为True
仓库类型:
hosted:本地仓库,通常我们会部署自己的构件到这一类型的仓库。比如公司的第二方库。
proxy:代理仓库,它们被用来代理远程的公共仓库,如maven中央仓库。
group:仓库组,用来合并多个hosted/proxy仓库。
3rd party、Snapshots、Releases这三个,分别用来保存第三方jar、项目组内部的快照、项目组内部的发布版。
选中Public Repositories,点击Configuration,可以看到当前添加到Public集合的仓库列表及顺序(优先级高的在上面,可用鼠标拖拽),当我们新增了仓库,将会出现在右侧的available Repository,添加到左边即可。如果有哪个仓库不想加入到该集合,也可以拖拽到右边来。
将Releases仓库的Deployment Policy设置为 Allow ReDeploy:
有些我们自己打的jar包(不存在于maven中央仓库中)或者maven本地仓库的jar,我们可以手工添加jar到我们的私服中:
填写完必选字段,点击Upload Artifact(s)按钮即可。
7.但是有时候我们需要将本地上传至私服仓库,但是我发现通过上面的操作只能一个一个上传,比较麻烦。
这时就采取了thirdparty这个仓库,服务器上对应仓库位置为/dev/nexus/sonatype-work/nexus/storage/thirdparty,通过ssh工具将本地maven库中所有的内容上传至该目录下:
登录maven私服,点击Repositories。在3rd party上右键点击Repair Index:
进入Public Repositories ,点击Refresh按钮,就可以看到本地仓库上传到私服了。
8.修改本地$MAVEN_HOME\conf目录下的settings.xml配置文件
添加如下配置:
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
添加镜像:
<mirror>
<id>nexus</id>
<mirrorOf>central</mirrorOf>
<url>http://ip:8081/nexus/content/groups/public/</url>
</mirror>
添加profile:
<profile>
<id>nexus</id>
<repositories>
<!-- 私有库地址-->
<repository>
<id>central</id>
<url>http://ip:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<!--插件库地址-->
<pluginRepository>
<id>central</id>
<url>http://ip:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!--**profile-->
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
9.配置项目pom.xml
<distributionManagement>
<repository>
<id>releases</id>
<name>Nexus Release Repository</name>
<url>http://ip:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://ip:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
至此,maven的私有库搭建完成。