zoukankan      html  css  js  c++  java
  • Nexus私服搭建

     MavenMaven默认提供的中央仓库是在远程网络服务Appache提供的,这对于我们开发时不合理的。

     如果我们在内网环境或者网速很不好的情况下,我们怎么办?也就是说我们对中央仓库的依赖性太大。而Nexus私服则可以解决我们这个问题。

    先看下这张图,应该大家就能明白了.

    这样就相当于在我们本地的局域网搭建了一个类似中央仓库的服务器,我们开始将中央仓库的一些资料下载到私服务器上,然后平时我们的maven项目就是直接访问局域网内的私服即可,既节省了网络带宽也会加速项目搭建的进程,这样对我们开发来说,对公司来说都是非常好的选择。下边简单看一下Nexus私服的简单使用:

        1、Nexus下载

        下载地址:http://www.sonatype.org/nexus/go

        " Download and Install Nexus OS",下载这个就可以。找最新的下载,目测是免费的。

     

        2、Nexus启动

        我下载的是nexus-2.11.4-01-bundle.tar.gz.

        root用户

          mkdir -p /usr/local/nexus-2.11.4

          tar  zxvf nexus-2.11.4-01-bundle.tar.gz -C /usr/local/nexus-2.11.4/

          cd /usr/local/nexus-2.11.4/nexus-2.11.4-01/bin/

       ./nexus --help

          ./nexus start

    假如提示“export RUN_AS_USER=root”,就在/etc/profile加上“export RUN_AS_USER=root”,然后source /etc/profile

    3.  ps aux |grep nexus

         netstat -lntup|grep 8081 (8081为默认的端口号,要修改端口号可进入conf exus.properties文件,修改application-port属性就可以了。)

    可检查才程序是否ok.

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

     4.点击右上角的Log in.

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

     

     

    5、Nexus仓库

        nexus的仓库类型分为以下四种:

                  group: 仓库组

                  hosted:宿主

                 proxy:代理

                 virtual:虚拟

       首次登陆nexus后可以看到以下一个仓库组和多个仓库。

     

     

        PublicRepositories:  仓库组

                      3rd party: 无法从公共仓库获得的第三方发布版本的构件仓库

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

                      Central: 用来代理maven中央仓库中发布版本构件的仓库

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

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

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

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

    6、配置nexus

     

        6.1、开启远程索引

        新搭建的neuxs环境只是一个空的仓库,需要手动和远程中心库进行同步,nexus默认是关闭远程索引下载,最重要的一件事情就是开启远程索引下载。登陆nexus系统,默认用户名密码为admin/admin123。

    点击左边Administration菜单下面的Repositories,找到右边仓库列表中的三个仓库Apache Snapshots,Codehaus Snapshots和Maven Central,然后再没有仓库的configuration下把Download Remote Indexes修改为true。如下图

     

     

        然后在Apache Snapshots,Codehaus Snapshots和Maven Central这三个仓库上分别右键,选择Repari Index,这样Nexus就会去下载远程的索引文件。

     

     

        这样设置以后, Nexus会自动从远程中央仓库下载索引文件, 为了检验索引文件自动下载是否生效,可以却换到Browse Index

     

     

        在左边菜单栏里面有个Artifact Search, 在输入框里面输入你想要搜索的构件名字,比如:maven, 那么查询结果如下:

     

     

        6.2 添加jboss 代理资源库

    maven默认的官方资源库http://repo1.maven.org/maven2/,很多第三方的jar包没有,所以我再添加一个jboss的资源库

    点击左侧的Repositories,然后再点击右侧的Add,会弹出下拉菜单,选择Proxy Repository

    Respository ID这里填写:jboss-public-repository-group (可以自已改名字)

    Respository Name这里填写:JBoss Public Maven Repository Group (可以自已改名字)

    其它项保持默认

    Remote Storage Location这里填写:https://repository.jboss.org/nexus/content/groups/public-jboss/ (这是jboss公布的公开资源库)

    把新添加的respoitory添加到Public Repositories组

     

     6.3  更新索引.

     

     

      7、settings.xml的配置  

    <settings>
      ...
     <profiles>
      <profile>
       <id>local_nexus</id>
       <repositories>
        <repository>
         <id>local_nexus</id>
         <name>local_nexus</name>
         <url>http://ip:8081/nexus/content/groups/public/</url>
         <releases>
          <enabled>true</enabled>
         </releases>
         <snapshots>
          <enabled>true</enabled>
         </snapshots>
        </repository>
       </repositories>
       <pluginRepositories>
        <pluginRepository>
         <id>local_nexus</id>
         <name>local_nexus</name>
         <url>http://ip:8081/nexus/content/groups/public/</url>
         <releases>
          <enabled>true</enabled>
         </releases>
         <snapshots>
          <enabled>true</enabled>
         </snapshots>
        </pluginRepository>
       </pluginRepositories>
      </profile>
     </profiles>
     <activeProfiles>
      <activeProfile>local_nexus</activeProfile>
     </activeProfiles>
      ...
    </settings>

    8、 maven 项目 的pom.xml配置 
    <repositories>
     <repository>
      <id>local_nexus</id>
      <name>local_nexus</name>
      <url>http://localhost:8081/nexus/content/groups/public/</url>
      <releases>
       <enabled>true</enabled>
      </releases>
      <snapshots>
       <enabled>true</enabled>
      </snapshots>
     </repository>
    </repositories>
    <pluginRepositories>
     <pluginRepository>
      <id>local_nexus</id>
      <name>local_nexus</name>
      <url>http://localhost:8081/nexus/content/groups/public/</url>
      <releases>
       <enabled>true</enabled>
      </releases>
      <snapshots>
       <enabled>true</enabled>
      </snapshots>
     </pluginRepository>
    </pluginRepositories>

     

    9.ps

    转载自http://blog.csdn.net/liujiahan629629/article/details/39272321 ,小有改动,* *。

     

     


  • 相关阅读:
    优化页面响应时间
    php性能优化
    加快compser install 和update的方法
    好用的类库
    php会话(session)实现原理
    mysql引擎
    数据库事物四大特性
    数据库索引
    insert和insertSelective区别
    java面试题之int和Integer的区别
  • 原文地址:https://www.cnblogs.com/assassin1994/p/4680458.html
Copyright © 2011-2022 走看看