Ubuntu server下搭建Maven私服Nexus

 

  Ubuntu server下搭建Maven私服Nexus服务器

  Maven私服Nexus的做用,主要是为了节省资源,在内部做为maven开发资源共享服务器来使用。maven

  

  一、下载测试

  经过root用户进去Ubuntu serverthis

  $  cd /opturl

  $  wget http://download.sonatype.com/nexus/oss/nexus-2.10.0-02-bundle.tar.gzspa

  

  二、启动代理

  环境准备,启动nexus,必须先完成JDK环境的配置。code

  $  cd /opt/server

  $  tar -zxvf nexus-2.10.0-02-bundle.tar.gzxml

  $  cd /opt/nexus-2.10.0-02/bin

  $  vi nexus

  在启动文件nexus中增长nexus的启动用户,不然没权限启动,将报错以下:

  WARNING - NOT RECOMMENDED TO RUN AS ROOT

  If you insist running as root, then set the environment variable RUN_AS_USER=root before running this script

  因此要解决此问题,须要在启动文件nexus,加上RUN_AS_USER=root,如图所示

  

  保存退出以后,便可启动nexus,命令以下:

  $  ./nexus start  

  Starting Nexus OSS...
  Started Nexus OSS.

  表示启动成功,访问地址:http://ip:8081/nexus

 

  三、配置nexus

  登陆nexus,右上角Log In,默认登陆用户名密码:admin/admin123

  登陆以后,咱们能够点击左边菜单栏Repositories进入详细配置

  能够本身从新建立一个私服配置,这里咱们用系统在带的Public Repositories

  

  关于仓库的类型介绍  

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

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

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

  3rd party 第三方依赖的仓库,这个数据一般是由内部人员自行下载以后发布上去

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

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

 

  可是须要将其余几个代理的库配置映射到Public中,分别将Apache Snapshots、Central、Codehaus Sanpshots下Download Remote Indexes选项选择【true】,保存便可,默认是false,以下图

  

  把将类型为Proxy的库Apache Snapshots、Central、Codehaus Sanpshots配置到Public Repositories下,以下图:

  

  而后分别将Apache Snapshots、Central、Codehaus Sanpshots更新Index,在每个库上面右键操做Repair Index

  

  最后将Public Repositories操做Repair Index

  而后接能够测试maven仓库了。

 

  四、远程测试maven仓库

  在项目中,引用maven仓库。则须要项目的pom.xml文件中添加以下:  

<repositories>
    <repository>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <id>Public</id>
        <name>Public Repositories</name>
     <url>http://192.168.10.50:8081/nexus/content/groups/public/</url>
    </repository>
</repositories>                

 

  而后执行maven下载依赖jar,检测是否下载成功~在私服上,经过左边的Artifact Search 搜索窗口,查看jar包是否在私服下载成功。

  另外,一般咱们是修改本地的maven安装目录下的配置文件setting.xml,将本地仓库更换成私服仓库地址,保证本客户端上全部的项目都将使用私服,配置setting.xml以下:

  在<profiles></profiles>加入  

  <profile>
    <id>env-dev</id>
    <repositories>
      <repository>
        <id>Public</id>
        <name>Public Repositories</name>
        <url>http://192.168.10.50:8081/nexus/content/groups/public</url>
        <snapshots>
          <enabled>true</enabled>
        </snapshots>
        <releases>
          <enabled>true</enabled>
        </releases>
      </repository>
    </repositories>
  </profile>

  并在</profiles>以后中加入  

<activeProfiles>
    <activeProfile>env-dev</activeProfile>        
</activeProfiles>

  新建项目,构建并测试

  

  五、三方jar包入maven私服

  好比 有些第三方jar包,在maven中心仓库没有,这个时候就须要手动在本地将jar上传上去,以供本地其余用户使用,简单截图介绍

  

相关文章
相关标签/搜索