码迷,mamicode.com
首页 > 其他好文 > 详细

nexus 搭建maven本地仓库

时间:2016-12-17 13:46:16      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:大量   依赖   mon   central   unique   config   log   --   仓库   

阅读目录

 

     在工作中可能存在有些开发机器不能上网,大量的机器获取jar包会导致公司网络很慢,还有时候公司会自己发布自己的项目版本,其他的项目可能会依赖引用到,所以就需要用到Maven的本地仓库。

     下面就这个构建本地Maven仓库进行阐述。

Nexus

一:介绍

  Nexus是Maven的仓库管理器,用来搭建一个本地仓库服务器,这样做的好处便于管理,节约网络资源, 速度快,可以通过SNAPSHOT版本控制,开进行模块间的高效依赖开发。

二:下载

  我们从http://nexus.sonatype.org/downloads/ 来获取最新版本。这里使用的是nexus-2.12.0-01-bundle.zip。

三:解压

  解压到本地后,目录结构。

  在bin里我们可以看到nexus.bat。到时候我们可以通过这个命令来安装卸载,启动停止nexus服务。

技术分享

四:配置环境变量

  由于是用java开发的。所以需要安装jdk,并配置好java的环境变量,这里就不表了。

  新建环境变量Nexus

  值为解压的目录 F:\nexus-2.12.0-01\ 

  path中加入;%Nexus%\bin

  可以看到

技术分享

   这样即可。从图中我们可以看到命令:start,stop等。

五:安装服务,启动服务

  我们先安装服务。

 nexus.bat install

  这样就可以安装了,提示安装好后。我们可以启动服务。

nexus.bat start

  提示成功后我们可以输入127.0.0.1:8081/nexus可以访问到。

技术分享

六:使用

  右上角有个Log in。点击这个可以登录。用户名是admin 密码默认的是 admin123

技术分享

  登录后,点击左边Views/Repositores下的Repositories

技术分享 

  hosted:本地仓库,通常我们会部署自己的构件到这一类型的仓库。比如公司的第二方库。 
  proxy:代理仓库,它们被用来代理远程的公共仓库,如maven中央仓库。 
  group:仓库组,用来合并多个hosted/proxy仓库,当你的项目希望在多个repository使用资源时就不需要多次引用了,只需要引用一个group即可。

  Central:是Maven的中央仓库,我们这里就那这个举例。

  选择仓库的类型

  Repository Policy 是Release 还是Snapshot

  下载远程索引文件

  点击Central这个仓库,然后点击Configration。在Download Remote Indexes改成True保存即可。

技术分享

  由于索引比较大,所以得过段时间才能下载完毕。

  Routing选项可以看到当前仓库与远程仓库的状态。并且制定更新频率。

技术分享

  将设置好的仓库放进仓库组里。

  点击Public Repositories->Configuration

  将Central放到左边即可。

技术分享

  点击Browse Index我们就可以看到很多仓库的资源了。

技术分享

  配置Maven,打开\apache-maven-3.3.3\conf\settings.xml配置文件。

  在<mirror>节点配置如下即可

技术分享
  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     | -->
    <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://127.0.0.0:8081/nexus/content/groups/public/</url>
    </mirror>
    
  </mirrors>
技术分享

技术分享

  我们在Elipse里就可以使用这个配置到的本地仓库了。

nexus 搭建maven本地仓库

标签:大量   依赖   mon   central   unique   config   log   --   仓库   

原文地址:http://www.cnblogs.com/bkyliufeng/p/6189319.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!