如果构建的Maven 项目本地仓库没有对应的依赖包,那么就会去Nexus 私服去下载,那么如果Nexus 私服也没有此依赖包,就回去远程中央仓库下载依赖,Nexus 私服下载成功后再下载至本地Maven 库供项目引用。
maven私服器Sonatype Nexus的安装与配置
1、安装
1.1 下载 Nexus(这里使用的是:nexus-2.11.2-03-bundle.tar.gz)
http://www.sonatype.org/nexus/go/
1.2 解压:因为解压后有两个文件夹,所以这里新建了一个nexus文件夹
1
2
3
4
5
6
|
[root
@localhost
opt]
# mkdir nexus
[root
@localhost
opt]
# tar -zxvf /opt/tar/nexus-2.11.2-03-bundle.tar.gz -C /opt/nexus/
[root
@localhost
opt]
# cd nexus/
[root
@localhost
nexus]
# ls
nexus-2.11.2-03 sonatype-work
[root
@localhost
nexus]
#
|
(一个 nexus 服务,一个私有库目录)
1.3 编辑 Nexus 的 nexus.properties 文件,配置端口和 work 目录信息(保留默认)
[root@localhost conf]# cat nexus.properties
1
2
3
4
5
6
7
8
9
|
# Jetty section
application-port=8081
application-host=0.0.0.0
nexus-webapp=${bundleBasedir}/nexus
nexus-webapp-context-path=/nexus
# Nexus section
nexus-work=${bundleBasedir}/../sonatype-work/nexus
runtime=${bundleBasedir}/nexus/WEB-INF
|
1.4 编辑 nexus 脚本
1
2
3
4
|
vi /opt/nexus/nexus-2.11.2-03/bin/nexus
#改成root
RUN_AS_USER=root
|
1.5 启动
1
|
/opt/nexus/nexus-2.11.2-03/bin/nexus start
|
1.6 访问:http://192.168.175.9:8081/nexus
1.7 登录,默认用户名 admin,默认密码 admin123
到此,Nexus 已安装完成,接下来是 Nexus 的配置
2、配置(登录后)
2.1 菜单 Administration/Server 配置邮箱服务地址(如果忘记密码,可以通过该邮箱找回密码)
测试邮箱:
给用户配置邮箱地址,方便忘记密码时找回:
2.2 修改密码
2.3 仓库
group仓库组:
Nexus 通过仓库组的概念统一管理多个仓库,这样我们在项目中直接请求仓库组即可请求到仓库组管理的多个仓库
hosted宿主仓库:
主要用于发布内部项目构件或第三方的项目构件(如购买商业的构件)以及无法从公共仓库获取的构件(如 oracle 的 JDBC 驱动)
proxy代理仓库:
代理公共的远程仓库;
virtual虚拟仓库:
用于适配 Maven 1;
一般用到的仓库种类是 hosted、proxy。
Hosted仓库常用类型说明:
releases:内部的模块中 release 模块的发布仓库
snapshots:发布内部的 SNAPSHOT 模块的仓库
3rd party:第三方依赖的仓库,这个数据通常是由内部人员自行下载之后发布上去
如果构建的Maven项目本地仓库没有对应的依赖包,那么就会去Nexus私服去下载,如果Nexus私服也没有此依赖包,就回去远程中央仓库下载依赖,这些中央仓库就是proxy 。Nexus私服下载成功后再下载至本地Maven库供项目引用。
设置proxy代理仓库(Apache Snapshots/Central/Codehaus Snapshots)准许远程下载:
注意:这里3个proxy都设置
setting.xml配置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
settings
xmlns
=
"http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
=
"http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"
>
<
localRepository
>G:\workspace\maven_space</
localRepository
>
<
interactiveMode
>true</
interactiveMode
>
<
offline
>false</
offline
>
<
pluginGroups
>
</
pluginGroups
>
<!--配置权限,使用默认用户-->
<
servers
>
<
server
>
<
id
>nexus-releases</
id
>
<
username
>deployment</
username
>
<
password
>deployment123</
password
>
</
server
>
<
server
>
<
id
>nexus-snapshots</
id
>
<
username
>deployment</
username
>
<
password
>deployment123</
password
>
</
server
>
</
servers
>
<
mirrors
>
</
mirrors
>
<
profiles
>
<
profile
>
<
id
>edu</
id
>
<
activation
>
<
activeByDefault
>false</
activeByDefault
>
<
jdk
>1.6</
jdk
>
</
activation
>
<
repositories
>
<!-- 私有库地址
仓库组
-->
<
repository
>
<
id
>nexus</
id
>
<
url
>http://192.168.175.9:8081/nexus/content/groups/public/</
url
>
<
releases
>
<
enabled
>true</
enabled
>
</
releases
>
<
snapshots
>
<
enabled
>true</
enabled
>
</
snapshots
>
</
repository
>
</
repositories
>
<
pluginRepositories
>
<!--插件库地址-->
<
pluginRepository
>
<
id
>nexus</
id
>
<
url
>http://192.168.175.9:8081/nexus/content/groups/public/</
url
>
<
releases
>
<
enabled
>true</
enabled
>
</
releases
>
<
snapshots
>
<
enabled
>true</
enabled
>
</
snapshots
>
</
pluginRepository
>
</
pluginRepositories
>
</
profile
>
</
profiles
>
<!--激活profile-->
<
activeProfiles
>
<
activeProfile
>edu</
activeProfile
>
</
activeProfiles
>
</
settings
>
|
项目的构建与发布:pom.xml
1
2
3
4
5
6
7
8
9
10
11
12
|
<
distributionManagement
>
<
repository
>
<
id
>nexus-releases</
id
>
<
name
>Nexus Release Repository</
name
>
<
url
>http://192.168.175.9:8081/nexus/content/repositories/releases/</
url
>
</
repository
>
<
snapshotRepository
>
<
id
>nexus-snapshots</
id
>
<
name
>Nexus Snapshot Repository</
name
>
<
url
>http://192.168.175.9:8081/nexus/content/repositories/snapshots/</
url
>
</
snapshotRepository
>
</
distributionManagement
>
|
发布到私有库:
pom:<version>1.0-SNAPSHOT</version>
pom:<version>1.0-RELEASES</version>
4、上传第三方jar,如:demo.jar
配置其开机启动
1、负责nexus到/etc/init.d下
1
|
cp /opt/nexus/nexus-2.11.2-03/bin/nexus /etc/init.d/nexus
|
2、修改nexus
1
2
|
[root
@localhost
~]
# vi /etc/init.d/nexus
NEXUS_HOME=
"/opt/nexus/nexus-2.11.2-03/"
|
3、修改wrapper.conf
1
2
|
[root
@localhost
~]
# vi /opt/nexus/nexus-2.11.2-03/bin/jsw/conf/wrapper.conf
wrapper.java.command=/home/jdk1.7.0_71/bin/java
|
4、添加脚本的可执行权限
1
|
chmod
755 /etc/init.d/nexus
|
5、添加为系统服务
1
|
chkconfig --add nexus
|