nexus2.x搭建maven私服教程(windows环境)

nexus

  1. 下载
    官网地址https://www.sonatype.com/download-oss-sonatype
    我下载的版本是nexus-2.14.4-03-bundle.tar.gz
  2. 解压
    解压后有两个文件夹如下
  3. 安装启动
    双击nexus-2.14.4-03,双击bin,双击jsw如下
    这里写图片描述
    这里是各种环境的安装方式,大家请自行选择。我选择的是windows-x86-32
    这里写图片描述
    console-nexus:启动nexus并在cmd中展示启动过程。
    install-nexus:将nexus设置成windows服务,开机自动启动。
    start-nexus:启动nexus。
    stops-nexus:停止nexus。
    uninstall-nexus:没用过字面意思应该是卸载暂时不使用。
    第一次启动选择前3个都可以看自己需求。为方便启动和退出Nexus,可将bin目录添加到环境变量path中。(如果不会配置环境变量请自行百度)配好环境变量后在cmd中键入nexus可以查看相应命令。键入nexus 命令(nexus start) 即可。
    nexus2.6以后至少要求安装jdk1.7以上才能正常启动
    这里写图片描述
    启动成功后,打开localhost:8081/nexus,进入如下页面
    这里写图片描述
    点击右上角login登陆,默认账号密码 admin/admin123,后面可根据需求自行修改。
  4. 从中央库下载索引到私服中央库
    依次点击1.左边的Repositories 2.点击Central 3.点击下面的Configuration 4.找到Download Remote Indexes 5.选择true 6.右键Central选择repair index或者update index都行
    这里写图片描述
    至此私服就开始向中央库下载更新索引了(前提你要有网络,否则会失败)
    点击左边的Administration下的Scheduled Tasks可以查看当前任务进度。如果状态为running则标示任务已经开始执行。
    这里写图片描述
    更新索引会花费比较多的时间大概半小时到1小时左右。
    如果想看进度可以打开nexus-2.14.4-03文件夹->logs->wapper.log查看日志。
    这里写图片描述
    如果日志中出现
    jvm 1 | 2017-07-21 15:48:19,615+0800 INFO [pxpool-1-thread-1] admin org.sonatype.nexus.index.NexusScanningListener - Scanning of repositoryID="central" started.
    标示更新索引已经开始。如果之后再没有信息表示正在进行。如果更新失败log里也会显示。如果显示finished则表示更新索引成功。
    jvm 1 | 2017-07-21 15:53:18,583+0800 INFO [pxpool-1-thread-1] admin org.sonatype.nexus.index.NexusScanningListener - Scanning of repositoryID="central" finished
    到这里,maven的私服算是搭建完成了。

maven

  1. 下载
    官网地址http://maven.apache.org/download.cgi
    我下载的是版本是apache-maven-3.3.9-bin.zip
    这里写图片描述
  2. 解压
    解压后只有一个文件夹如下
    这里写图片描述
  3. 配置环境变量
    点击apache-maven-3.3.9文件夹->bin,复制目录,将该目录配置到环境变量path中即可。
    这里写图片描述
    当然,安装的前提是要安装了jdk。
  4. 验证是否安装成功
    打开cmd 输入mvn -v 信息如下则表示安装成功。
    这里写图片描述

将maven指向nexus私服

依次打开apache-maven-3.3.9->conf->settings.xml
添加服务验证

<server>
    <id>nexus</id>
    <username>admin</username>
    <password>admin123</password>
</server>

添加镜像

<mirror>   
        <id>nexus-mirror</id>   
        <mirrorOf>maven-central</mirrorOf>   
        <url>http://192.168.2.190:8081/nexus/content/repositories/central/</url>   
</mirror>

做构件的配置

<profile>
      <id>nexuesProfile</id>
      <repositories>
          <repository>
              <id>maven-central</id>
              <name>maven-central</name>
              <url>http://192.168.2.190:8081/nexus/content/repositories/central/</url>
              <snapshots>
                  <enabled>true</enabled>
              </snapshots>
              <releases>
                  <enabled>true</enabled>
              </releases>
          </repository>
      </repositories>
</profile>

激活构件

<activeProfiles>
      <activeProfile>nexuesProfile</activeProfile>
 </activeProfiles>

至此大功告成

下面贴上完整的settings.xml代码

<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <pluginGroups>
  </pluginGroups>

  <proxies>
  </proxies>

  <servers>
    <server>
      <id>nexus</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
  </servers>

  <mirrors>
    <mirror>   
       <id>nexus-mirror</id>   
       <mirrorOf>maven-central</mirrorOf>   
       <url>http://192.168.2.190:8081/nexus/content/repositories/central/</url>   
    </mirror>  
  </mirrors>

  <profiles>
    <profile>
      <id>nexuesProfile</id>
      <repositories>
        <repository>
          <id>maven-central</id>
          <name>maven-central</name>
          <url>http://192.168.2.190:8081/nexus/content/repositories/central/</url>
          <snapshots>
              <enabled>true</enabled>
          </snapshots>
          <releases>
              <enabled>true</enabled>
          </releases>
        </repository>
      </repositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>nexuesProfile</activeProfile>
  </activeProfiles>

</settings>

关于settings.xml的详细介绍请移步http://blog.csdn.net/Dynamic_W/article/details/77483311

猜你喜欢

转载自blog.csdn.net/Dynamic_W/article/details/75661204