Nexus(Maven私服)搭建的基本操作

安装nexus

下载nexus

访问nexus官方网站http://www.sonatype.org/nexus/,下载nexus-2.9.1-02-bundle.zip。 http://www.sonatype.org/nexus/archived

解压至某个目录(如E:\Eb\nexus-2.9.1-02-bundle)

开启jetty服务器。找到E:\Eb\nexus-2.9.1-02-bundle\nexus-2.9.1-02\bin\jsw\windows-x86-32(由于jdk安装的是32位版本,因此执行此目录下的文件)目录,执行console-nexus.bat批处理文件。

 

 

访问nexus管理页面

打开浏览器,输入http://localhost:8081/nexus/,点击页面右上方的Log in超链接,输入默认用户名密码admin/admin123,登录nexus管理页面。

 

配置nexus

登录nexus管理页面,点击左侧的Repositories,显示相关的仓库信息,各个仓库的含义可自行百度之。

选中Central,点击下方的Configuration选项卡。修改Download Remote Indexes项的值为True。点击页面下方的save按钮。

 

修改本地目录存储配置

直接修改E:\Eb\nexus-2.9.1-02-bundle\nexus-2.9.1-02\conf\nexus.properties中的配置项nexus-work如下

  1. # Nexus section  
  2. #nexus-work=${bundleBasedir}/../sonatype-work/nexus  
  3. nexus-work=H:/Eb/nexus-2.9.1-02-bundle/sonatype-work/nexus  
  4. runtime=${bundleBasedir}/nexus/WEB-INF  
这样就直接到H盘下
 

基本信息

登录成功后,选择左边 Views/Repositories 菜单下的 Repositories,可以看到一些预设的仓库,我们会用到的一般只有 Public Repositories 和 3rd party , Public Repositories 为公共仓库,3rd party 为第三方仓库,可以上传第三方的 Jar (当然也可以是自己封装的 Jar)。

 

添加阿里云仓库

阿里云的maven仓库地址:

http://maven.aliyun.com/nexus/content/groups/public

nexus里,Public Repositories是对外的出口,实际用了哪个库是在它的Configuration的配置的。
有个Ordered Group Repositories,里面有个Central库,它的

库地址是https://repo1.maven.org/maven2/,速度很慢

快捷方法

直接把Central的地址换成阿里云的

基本添加

增加一个Proxy Repository,id,name随便写,库地址就写http://maven.aliyun.com/nexus/content/groups/public
然后到Ordered Group Repositories这里把这个新加的库弄到左边。

再拖拽到Central库的上面,优先走阿里云的库,保存。

MAVEN XML的配置

 

Nexus 安装成功后,接下来需要修改 Maven 的配置文件(settings.xml),整合 Nexus。

找到 <servers> 标签,添加 Nexus 默认认证信息:

1
2
3
4
5
6
7
8
9
10
<server>   
     <id>my-nexus-releases</id>   
     <username>admin</username>   
     <password>admin123</password>   
   </server>   
   <server>   
     <id>my-nexus-snapshot</id>   
     <username>admin</username>   
     <password>admin123</password>   
   </server>

找到 <mirrors> 标签,添加镜像:

 

1
2
3
4
5
6
<mirror>
   <!--This sends everything  else  to / public  -->
   <id>nexus</id>
   <mirrorOf>*</mirrorOf>
   <url>http: //localhost:8081/nexus/content/groups/public/</url>
</mirror>

找到 <profiles> 标签,添加仓库信息:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<profile>
   <id>nexus</id>
   <!--Enable snapshots  for  the built in central repo to direct -->
   <!--all requests to nexus via the mirror -->
   <repositories>
     <repository>
       <id>central</id>
       <url>http: //central</url>
       <releases><enabled> true </enabled></releases>
       <snapshots><enabled> true </enabled></snapshots>
     </repository>
   </repositories>
  <pluginRepositories>
     <pluginRepository>
       <id>central</id>
       <url>http: //central</url>
       <releases><enabled> true </enabled></releases>
       <snapshots><enabled> true </enabled></snapshots>
     </pluginRepository>
   </pluginRepositories>
</profile>

激活仓库:

 

1
2
3
4
<activeProfiles>
   <!--make the profile active all the time -->
   <activeProfile>nexus</activeProfile>
</activeProfiles>

 

配置完成后保存,并重启 nexus  服务

重启  nexus  服务 完成后,在命令行窗口进入一个使用 Maven 构建的项目,输入 mvn package clean 命令,清理完成后,登录 nexus 的 admin 账号可以看到 Public Repositories  下出现了一些 Jar 包。

添加第三方JAR包

选择3rd party 库下面 afifact upload标签

GAV Definition  选择    GAV Parameters

Auto Guess 默认 √

Group:        com.solanexus

Artifact:         springandswagger

Version:         1.0

Packaging:     jar

 

下面select Artifact to upload 选择 要上传的jar包

选择好后,点击add Artifact会添加到下方的多行文本框。

最后点击 Upload Artifact 上传成功。

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值