Maven私服Nexus3.6.0

来源:互联网 发布:程序员入门培训 编辑:程序博客网 时间:2024/05/17 22:22

下载地址:https://www.sonatype.com/download-oss-sonatype
或者:https://help.sonatype.com/display/NXRM3/Download
这两个地址下载的结果是一样的。

这里是Nexus3.6.0的英文文档:https://help.sonatype.com/display/NXRM3/Installation

下载完Nexus3.6.0后解压,得到如下目录结构:
这里写图片描述
看下官网对这两个文件夹的描述:
这里写图片描述

After you extract the repository manager archive, two directories will appear:Installation directory----------------------    This directory is contains the Nexus Repository Manager application and all the required additional components such as Java libraries and configuration files. The name of the directory by default uses nexus- and is appended with the version name. In this section, and throughout the book, it is referred to as $install-dir in any code segments.Data directory--------------    This directory contains all the repositories, components and other data that are stored and managed by the repository manager. The default location of the data directory is  ../sonatype-work/nexus3 relative to the installation directory. In this section, and throughout the book, it is referred to as $data-dir in any code segments.

解压压缩文件后,得到两个文件夹:

安装目录

这个目录包含了Nexus仓库管理软件和所有必需的组件,例如Java库和配置文件等。这个目录默认以nexus-开始且后跟版本名,也就是nexus-3.6.0-02。在文档中,它就是 $install-dir的值。

数据目录

这个目录包含所有需要被Nexus仓库进行管理的的代理仓库,组件和数据。数据的默认位置是在/sonatype-work/nexus3下,在文档中,它就是 $data-dir的值。
关于这两个目录下的文件夹的说明情况:https://help.sonatype.com/display/NXRM3/Directories

启动Nexus3.6.0

需要的JAVA环境:Nexus Repository Manager requires a Java 8 Runtime Environment (JRE) from Oracle.

在控制台进入nexus-3.6.0-02\bin下,执行:nexus.exe /run,会下载很多东西,当你看到
这里写图片描述
则表明你的Nexus3.6.0启动成功。

Nexus的默认服务端口为8081,打开浏览器,输入:localhost:8081即可进入Nexus管理系统。
如果你的8081端口被占用,则进入nexus-3.6.0-02\etc下找到nexus-default.properties文件,打开修改端口号,保存,重新执行:nexus.exe /run

如果端口号没有被占用,则会看到如下界面:
这里写图片描述
点击右上角的Sign in,默认的用户名是:admin,密码:admin123。
官方文档描述如下:
这里写图片描述
关于这个私服环境的介绍,推荐这篇博客http://blog.csdn.net/fygkchina/article/details/62976387

注册Nexus3.6.0服务

官方文档说明地址:https://help.sonatype.com/display/NXRM3/Run+as+a+Service

进入nexus-3.6.0-02\bin下执行:

nexus.exe /install <optional-service-name>

optional-service-name是服务名称,可以随便起。
完成后就可以在任务管理器中找到该服务:
这里写图片描述
我这里取名为nexus3.6。

可以通过执行:

nexus.exe /uninstall <optional-service-name>

来注销服务,我试过了,好像并不能注销,妈蛋!
成功注册服务之后,启动Nexus3.6.0就有两种办法了:
(1)通过任务管理器来启动和关闭服务
(2)通过在G:\nexus-3.6.0-02-win64\nexus-3.6.0-02\bin下执行:nexus.exe /start nexus3.6和nexus.exe /stop nexus3.6来启动和关闭该服务。

配置Nexus3.6.0为代理仓库

官方文档关于这部分内容的说明地址:
https://help.sonatype.com/display/NXRM3/Maven+Repositories
这里写图片描述
为了让Apache Maven能使用Nexus作为代理仓库,需要将Maven默认连接中央仓库的配置修改为连接Nexus代理仓库。
因此,需要添加如下内容:

<settings>  <mirrors>    <mirror>      <!--This sends everything else to /public -->      <id>nexus</id>      <mirrorOf>*</mirrorOf>      <url>http://localhost:8081/repository/maven-public/</url>    </mirror>  </mirrors>  <profiles>    <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>  </profiles>  <activeProfiles>    <!--make the profile active all the time -->    <activeProfile>nexus</activeProfile>  </activeProfiles></settings>

来覆盖~/.m2/settings.xml中的默认配置。
不要直接复制全部粘贴过去,
复制:

    <mirror>      <!--This sends everything else to /public -->      <id>nexus</id>      <mirrorOf>*</mirrorOf>      <url>http://localhost:8081/repository/maven-public/</url>    </mirror>

添加到settings.xml的<mirrors></mirrors>标签中,
复制:

    <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>

添加到settings.xml的<profiles></profiles>标签中,
复制:

  <activeProfiles>    <!--make the profile active all the time -->    <activeProfile>nexus</activeProfile>  </activeProfiles>

添加到settings.xml的<settings></settings>标签中。

第二步:在你的maven目录conf下的settings.xml中的<servers></servers>标签中添加如下:

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

第三步:
在项目的pom.xml的<project></project>标签下添加如下:

<distributionManagement>    <repository>      <id>nexus</id>      <name>Releases</name>      <url>http://localhost:8081/repository/maven-releases</url>    </repository>    <snapshotRepository>      <id>nexus</id>      <name>Snapshot</name>      <url>http://localhost:8081/repository/maven-snapshots</url>    </snapshotRepository>  </distributionManagement>

配置上面这个是为了将自己的项目发布到Nexus3.6.0上,这样在分布式开发的时候,如果别人需要调用你的代码作为依赖,就可以直接去Nexus3.6.0上找并配置到它们的pom.xml中即可。
以上是个人学习官方文档时的笔记,如果有错误,欢迎指正,毕竟英文不太好,看起来贼吃力。