maven搭建nexus私服在myeclipse中的使用

maven搭建nexus私服在myeclipse中的使用

1、简介

这里主要是对maven和nexus私服的使用。nexus私服,可以理解为在本地局域网建立了一个类似中央仓库的处理器,我们开始将资料下载到中央服务器中,然后在本地maven项目中直接访问中央服务器即可,这样既

节省了网络宽带也会加速项目的开发进度,图如下展示:

wKioL1cwxKHghw9BAACGu-_9HUo721.jpg

2、下载私服到本地并安装

wKioL1cwxKHi9VCqAADobN0uRYk410.jpg

点击NUEXS OSS(ZIP),会让输入邮箱,无视即可,如果不自动下载,那么复制URL链接到迅雷即可下载。

比如:https://sonatype-download.global.ssl.fastly.NET/nexus/oss/nexus-latest-bundle.zip

解压nexus-latest-bundle.zip,进入http://item.taobao.com/item.htm?id=41222768202

双击console-nexus.bat安装,会弹出DOS框,等着安装完,中间别关掉DOS框。

wKiom1cww8ThSE5dAAAN69kMTXQ371.png

3、操作NEXUS

游览器中输入http://127.0.0.1:8081/nexus/,出现如下图所示就代表nexus已经启动成功。

8081为默认的端口号,要修改端口号可进入nexus-2.1.2-bundle\nexus-2.1.2\conf\打开nexus.properties文件,修改application-port属性值就可以了。

默认的用户名和密码:admin/admin123,登录后看到如下图所示:wKiom1cww8SwGT6mAABMXEaRk2A216.png

下面关于上述图中某几列的解释:

-------------------------------------------------------------------------------------

TYPE:

hosted   类型的仓库,内部项目的发布仓库

releases 内部的模块中release模块的发布仓库

snapshots 发布内部的SNAPSHOT模块的仓库

proxy   类型的仓库,从远程中央仓库中寻找数据的仓库

group   类型的仓库,组仓库用来方便我们开发人员进行设置的仓库

-------------------------------------------------------------------------------------

REPOSITORY:

PublicRepositories:  仓库组

3rd party: 无法从公共仓库获得的第三方发布版本的构件仓库(个人理解操作:maven仓库中没有的,需要手工传到仓库中的jar包)

Apache Snapshots: 用了代理ApacheMaven仓库快照版本的构件仓库

Central: 用来代理maven中央仓库中发布版本构件的仓库(个人理解操作:maven仓库)

Central M1 shadow: 用于提供中央仓库中M1格式的发布版本的构件镜像仓库

Codehaus Snapshots: 用来代理CodehausMaven 仓库的快照版本构件的仓库

Releases: 用来部署管理内部的发布版本构件的宿主类型仓库

Snapshots:用来部署管理内部的快照版本构件的宿主类型仓库

-------------------------------------------------------------------------------------

理解:

一般用到的仓库种类是hosted、proxy。Hosted代表宿主仓库,用来发布一些第三方不允许的组件,比如Oracle驱动、比如商业软件jar包。Proxy代表代理远程的仓库,最典型的就是Maven官方中央仓库、JBoss仓库等等。如果构建的Maven项目本地仓库没有依赖包,那么就会去这个代理站点去下载,那么如果代理站点也没有此依赖包,就回去远程中央仓库下载依赖,这些中央仓库就是proxy。代理站点下载成功后再下载至本机。笔者认为,其实Maven这个自带的默认仓库一般情况下已经够大多数项目使用了。特殊情况时在配置新的仓库,指定url即可,一般熟悉ExtJS的人操作这个Nexus都没什么问题,单词不是很难,不明白的查查单词基本差不多。就是如果Sonatype公司对其做了国际化的处理就更好了。

Nexus 中仓库组的概念是Maven没有的,在Maven看来,不管你是hosted也好,proxy也好,或者group也好,对我都是一样的,我只管根据 groupId,artifactId,version等信息向你要构件。为了方便Maven的配置,Nexus能够将多个仓库,hosted或者 proxy合并成一个group,这样,Maven只需要依赖于一个group,便能使用所有该group包含的仓库的内容。http://item.taobao.com/item.htm?id=41222768202

-------------------------------------------------------------------------------------

4、nexus配置(maven的配置参考maven-使用部分。)

4、1利用现有nexus索引配置

需要的索引有Public Repositories,3rd party和Central。如果新建的nexus跟下述图中的属性不一致,需要调整。

--------------------------------------------------------------------------------------------

Public Repositories部分,需要注意左下方的顺序:

wKioL1cwxKLAQniKAAEUmdp3R-E719.jpg

--------------------------------------------------------------------------------------------

3rd party部分:

wKioL1cwxKLCnI-dAABQBWziCQ4872.png

wKiom1cww8WggHyLAAAvU-5A_nc853.png

在本地加入maven库中不存在的第三方jar包,比如oracle的jar包:

wKiom1cww8ay86UPAACviPePs9M845.png

wKioL1cwxKPA74baAAA1s4qOE2Q467.png

wKiom1cww8bgfoMXAAAaMNDiuPM079.png

wKioL1cwxKOzwoSzAADNFLUROro227.jpg

--------------------------------------------------------------------------------------------

Central部分:

新搭建的neuxs环境只是一个空的仓库,需要手动和远程中心库进行同步,nexus默认是关闭远程索引下载,最重要的一件事情就是开启远程索引下载。把download remote indexes改成true。http://item.taobao.com/item.htm?id=41222768202

wKioL1cwxKSA_P-vAABHQWiB_iU285.png

wKiom1cww8fR1v01AAA35U2kMTQ054.png

wKioL1cwxKSiIyDHAAA2HqslfgU121.png

保存后后台会运行一个任务,点击菜单栏的administration -- Scheduled Tasks选项即可看到有个任务在RUNNING。

wKiom1cww8ezfdhoAAAcWYZEl6Q018.png

下载完成后,Maven索引就可以使用了,在搜索栏输入要搜索的项,就可以查到相关的信息。

wKioL1cwxKXxjscEAAEKdvB8Ea8680.jpg

或者在主页面搜索可跳转到上述页面。

wKiom1cww8iBe6PlAACAlw4A5fE079.png

都点击SAVE按钮之后,右键每一个REPOSITORY,进行repair index操作,这样才会去下载远程索引文件。

wKiom1cww8jTaWMtAADYaG08PQE684.jpg


打开不同索引的browse index按钮,比如central的,会看到对应的jar包列表:

wKioL1cwxKWRR0lyAAAyYK6TFgk335.png

--------------------------------------------------------------------------------------------

在myeclipse中的maven工程配置pom.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
< 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/maven-v4_0_0.xsd" >
   < modelVersion >4.0.0</ modelVersion >
   < groupId >MavenTest01</ groupId >
   < artifactId >MavenTest01</ artifactId >
   < version >0.0.1-SNAPSHOT</ version >
   < packaging >war</ packaging >
   <!-- 版本属性 -->
< properties >
<!-- lib version setting -->
< spring.version >4.1.6.RELEASE</ spring.version >
< mybatis.version >3.2.8</ mybatis.version >
< mybatis-spring.version >1.2.2</ mybatis-spring.version >
< mysql.driver.version >5.1.35</ mysql.driver.version >
< druid.version >1.0.13</ druid.version >
<!-- project util lib version setting -->
< util.version >0.2.2-SNAPSHOT</ util.version >
<!-- util lib version setting -->
< log4j.version >1.2.17</ log4j.version >
< slf4j.version >1.7.7</ slf4j.version >
< jackson.version >2.5.1</ jackson.version >
< commons-lang3.version >3.3.2</ commons-lang3.version >
< commons-beanutils.version >1.9.2</ commons-beanutils.version >
< httpClient.version >4.5</ httpClient.version >
< gson.version >2.2.4</ gson.version >
< junit.version >4.11</ junit.version >
<!-- 编译jdk版本 -->
< jdk.version >1.7</ jdk.version >
</ properties >
<!-- 设定主仓库 -->
< repositories >
<!-- nexus私服 -->
< repository >
< id >nexus-repos</ id >
< name >Team Nexus Repository</ name >
< url >http://127.0.0.1:8081/nexus/content/groups/public/</ url >
< releases >
< enabled >true</ enabled >
</ releases >
< snapshots >
< enabled >true</ enabled >
</ snapshots >
</ repository >
</ repositories >
<!-- 设定插件仓库 -->
< pluginRepositories >
< pluginRepository >
< id >nexus-repos</ id >
< name >Team Nexus Repository</ name >
< url >http://127.0.0.1:8081/nexus/content/groups/public/</ url >
< releases >
< enabled >true</ enabled >
</ releases >
< snapshots >
< enabled >true</ enabled >
</ snapshots >
</ pluginRepository >
</ pluginRepositories >
< dependencies >
<!-- spring -->
< dependency >
< groupId >org.springframework</ groupId >
< artifactId >spring-core</ artifactId >
< version >${spring.version}</ version >
< exclusions >
< exclusion >
< groupId >commons-logging</ groupId >
< artifactId >commons-logging</ artifactId >
</ exclusion >
</ exclusions >
</ dependency >
< dependency >
< groupId >org.springframework</ groupId >
< artifactId >spring-beans</ artifactId >
< version >${spring.version}</ version >
</ dependency >
< dependency >
< groupId >org.springframework</ groupId >
< artifactId >spring-context</ artifactId >
< version >${spring.version}</ version >
</ dependency >
< dependency >
< groupId >org.springframework</ groupId >
< artifactId >spring-aop</ artifactId >
< version >${spring.version}</ version >
</ dependency >
< dependency >
   < groupId >com.oracle</ groupId >
   < artifactId >odbc</ artifactId >
   < version >10.1.0.2.0</ version >
</ dependency >
< dependency >
< groupId >org.mybatis</ groupId >
< artifactId >mybatis-spring</ artifactId >
< version >${mybatis-spring.version}</ version >
</ dependency >
</ dependencies >
< build >
< plugins >
< plugin >
< groupId >org.apache.maven.plugins</ groupId >
< artifactId >maven-compiler-plugin</ artifactId >
< configuration >
< source >${jdk.version}</ source >
< target >${jdk.version}</ target >
</ configuration >
</ plugin >
</ plugins >
< finalName >MavenTest01</ finalName >
</ build >
</ project >

-------------------------------------------------------------------------------------------

注意:

其中上述pom.xml文件中的URL:<url>http://127.0.0.1:8081/nexus/content/groups/public/</url>

http://item.taobao.com/item.htm?id=41222768202

里面的public为:REPOSITORY的Public Repositories的Group ID:public

wKioL1cwxKbilJLVAAAWiwBKf_w653.png

当maven工程编译成功之后,nexus库在本地的jar包路径为:E:\nexus\nexus-latest-bundle-zip\sonatype-work\nexus\storage\central

而maven工程下载到本地maven库的路径为:E:\maven\repository

这两者不要混淆。

-------------------------------------------------------------------------------------------

4、2如果不使用nexus已存在的索引,需要新建本地nexus索引的话,那么大致内容同上述nexus已配置好的索引内容。

-------------------------------------------------------------------------------------------

注意,下述自己新建的部分弄完之后别忘记保存和repair index操作。

在maven项目中的pom.xml需修改URL为:<url>http://127.0.0.1:8081/nexus/content/groups/public-snapshots/</url>,其他内容同上述pom.xml。

当pom.xml改造完成之后,注意:maven项目会先从本地nexus仓库中取对应的jar包,如果本地仓库没有,那么就会去外网maven仓库中去取jar包。

-------------------------------------------------------------------------------------------

分别新建,group,hosted,proxy

wKiom1cww8nQW8CGAAAlLx5BkdU754.png

hosted宿主仓库部分,根据3rd party操作:

wKioL1cwxymxATcHAABGW7blI2E862.png

wKiom1cww8mTvDTLAAAnk2LjoOk402.png

proxy代理仓库部分,根据central部分操作:

wKioL1cwxKagmFW0AAAv9IH47IE727.png

wKioL1cwxKfAbIPpAAAyzH-UPeA465.png

wKiom1cww8qSeZK4AAAQhamQpII623.png

group仓库组部分,根据Public Repositories操作,要注意左下角的添加顺序:

wKiom1cww8rwpX2kAABOs6SZe0Q899.png

之后会在对应的group,hosted和proxy中查询到对应的jar包:

wKioL1cwxKejQW4_AAAp6lsLxN4833.png

wKiom1cww8qSsLzuAAAef8owwvo897.png

wKioL1cwxKeC8LU_AAAh7FmA_kI957.png

注意:可以发现group包括了hosted和proxy,这里面只对应maven工程对应pom.xml中的所有jar包。而my3rdParty是第三方的,而mycentral中包括maven库中所有的jar包。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值