搭建Maven私服

本文地址:搭建Maven私服
环境信息:
Linux:CentOS release 6.5 (Final)
Nexus:2.14.2-01


1、安装服务器

1.1、下载

下载如下文件(下载地址):
下载nexus

1.2、解压

解压下载的文件:

1
tar xzvf nexus-oss-webapp-1.8.0-bundle.tar.gz

1.3、启动

进入/nexus-2.14.2-01/bin目录,看到Started Nexus OSS.就说明已经完成启动。
启动nexus

1.4、访问

通过查看/nexus-2.14.2-01/logs/wrapper.log日志文件,查看对应的端口号
nexus-port

也可以查看配置文件查看配置的端口号,application-port对应的配置即为对应的端口号,此时配置是8888,默认为8081
/nexus-2.14.2-01/conf/nexus.properties
nexus.properties

我们可以在浏览器中通过下面URL进行访问,
默认用户名和密码:admin/admin123
http://192.168.33.107:8081/nexus/
注意: 如果无法访问,可能是防火墙没有开放8081端口

其中默认用户名密码配置文件位置在:/sonatype-work/nexus/conf/security.xml文件中
nexus-user

2、配置Nexus

2.1、修改配置

通过admin用户登录后
nexus-configuration

2.2、更新索引

nexus-updateIndex

2.3、推荐设置

2.1中的Remote Storage Location(远程仓库地址)设置是可选操作,不过,建议设置,可以加快jar下载速度。
(阿里云中央仓库地址:http://maven.aliyun.com/nexus/content/groups/public/)

3、在项目中使用私服

在pom.xml中增加repositories及pluginRepositories配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<repositories>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>public</id>
<name>Public Repositories</name>
<url>http://192.168.33.107:8081/nexus/content/groups/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public</id>
<name>Public Repositories</name>
<url>http://192.168.33.107:8081/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
</project>