一、下载最新版本的nexus

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

2、官网如果下载不了,就找个zip下载,我下载的是:nexus-2.10.0-02-bundle.zip

3、 解压zip文件,出现两个文件夹:

   

4、 打开D:\tools\Nexus-oss\nexus-2.10.0-02\bin\jsw\,选择合适的系统,打开对应的文件夹:

  

二、安装nexus

1、安装

  点击install-nexus.bat,然后访问http://localhost:8081/nexus/ 启动后如下页面,在右上角有个Log in 的超链接,点击登录

默认的用户名是 admin 密码是 admin123

  

2、修改登录信息:

  

3、配置代理

配置一下maven的代理服务器(前提是你的电脑不能连接外网,如果可以上外网,这里也没有意思,只是介绍一下)

  

添加你的代理服务器就可以了。

4、使用3rd party

使用3rd party这个第三方的功能,将maven仓库中没有构件的jar包上传到服务器

  

5、修改central repo的默认地址

maven3使用nexus作为代理服务器时需要修改中央库的url地址,maven默认的中央库的地址是http://repo.maven.apache.org/maven2/,而nexus默认的中央代理库的地址是http://repo1.maven.org/maven2/,可能是maven3启用了新的中央库,解决办法是:

修改nexus的中央库central配置:

把默认的中央库的url:http://repo1.maven.org/maven2/

修改为: http://repo.maven.apache.org/maven2/

三、 在项目中配置Nexus Repository的信息

配置工程的pom.xml,使用nexus repository的jar包:

1、添加本地仓库地址

在Maven项目的pom.xml中添加如下的本地仓库地址:

<repositories>

<repository>

<id>nexus</id>

<name>nexus</name>

<url>http://10.10.10.41:8081/nexus/content/groups/public/</url>

<releases>

<enabled>true</enabled>

</releases>

<snapshots>

<enabled>true</enabled>

</snapshots>

</repository>

</repositories>

2、添加插件仓库地址:

在Maven项目的pom.xml中添加如下的本地仓库地址:

<pluginRepositories>

<pluginRepository>

<id>nexus</id>

<name>nexus</name>

<url>http://10.10.10.41:8081/nexus/content/groups/public/</url>

<releases>

<enabled>true</enabled>

</releases>

<snapshots>

<enabled>true</enabled>

</snapshots>

</pluginRepository>

</pluginRepositories>

3、分发构件至远程仓库

mvn install 会将项目生成的构件安装到本地Maven仓库,mvn deploy 用来将项目生成的构件分发到远程Maven仓库。本地Maven仓库的构件只能供当前用户使用,在分发到远程Maven仓库之后,所有能访问该仓库的用户都能使用你的构件。

所以我们需要配置工程中POM的distributionManagement来指定Maven分发构件的位置

<distributionManagement>

<repository>

<id>releases</id>

<name>Nexus Release Repository</name>

<url>http://10.10.10.41:8081/nexus/content/repositories/releases/</url>

</repository>

<snapshotRepository>

<id>snapshots</id>

<name>Nexus Snapshot Repository</name>

<url>http://10.10.10.41:8081/nexus/content/repositories/snapshots/</url>

</snapshotRepository>

</distributionManagement>

四、用Nexus Repository取代Maven Central Repository

配置maven的settings.xml文件

4.1、文件存放位置

全局配置: ${M2_HOME}/conf/settings.xml

用户配置: ${user.home}/.m2/settings.xml

备注:用户配置优先于全局配置。${user.home} 和和所有其他系统属性只能在3.0+版本上使用。请注意windows和Linux使用变量的区别。

4.2、配置server

<servers>

<server>

<id>releases</id>

<username>admin</username>

<password>admin123</password>

</server>

<server>

<id>snapshots</id>

<username>admin</username>

<password>admin123</password>

</server>

<server>

<id>nexus</id>

<username>admin</username>

<password>admin123</password>

</server>

</servers>

备注:settings.xml中server元素下id的值必须与POM中repository下id的值完全一致。将认证信息放到settings下而非POM中,是因为POM往往是他人可见的,而settings.xml是本地的。

4.3、用Nexus取代Maven Central Repository

目前我们只是创建了一个专属的Nexus Repository,我们的项目默认还是使用的Maven Central Repository,所以这时我们需要将Maven Central Repository换成自己创建的Nexus Repository,可以通过修改~/.m2/settings.xml来达到这样的目的。

在settings.xml文件中(没有的话可以创建一个),加入以下配置:

<mirrors>

<mirror>

<id>nexus-releases</id>

<mirrorOf>*</mirrorOf>

<url>http://10.10.10.41:8081/nexus/content/groups/public</url>

</mirror>

<mirror>

<id>nexus-snapshots</id>

<mirrorOf>*</mirrorOf>

<url>http://10.10.10.41:8081/nexus/content/groups/public-snapshots</url>

</mirror>

</mirrors>

<profiles>

<profile>

<id>nexus</id>

<repositories>

<repository>

<id>releases</id>

<url>http://10.10.10.41:8081/nexus/content/repositories/releases</url>

<releases><enabled>true</enabled></releases>

<snapshots><enabled>true</enabled></snapshots>

</repository>

<repository>

<id>snapshots</id>

<url>http://10.10.10.41:8081/nexus/content/repositories/snapshots</url>

<releases><enabled>true</enabled></releases>

<snapshots><enabled>true</enabled></snapshots>

</repository>

</repositories>

<pluginRepositories>

<pluginRepository>

<id>releases</id>

<url>http://10.10.10.41:8081/nexus/content/repositories/releases</url>

<releases><enabled>true</enabled></releases>

<snapshots><enabled>true</enabled></snapshots>

</pluginRepository>

<pluginRepository>

<id>snapshots</id>

<url>http://10.10.10.41:8081/nexus/content/repositories/snapshots</url>

<releases><enabled>true</enabled></releases>

<snapshots><enabled>true</enabled></snapshots>

</pluginRepository>

</pluginRepositories>

</profile>

</profiles>

以上配置通过mirror和profile的方式将central Repository全部转向到我们自己的Public Repositories,包括release版本和snapshot版本(Maven默认允许从Maven Central Repository下载release版本,这是合理的,如果你使用了别人的snapshot版本,一边你在使用,一边别人在开发,别人将API签名一换,你就悲剧了)。这样一来,我们项目中的所有依赖都从Nexus的Public Repositories下载,由于其中包含了对Maven Central Repository的代理,所以此时Maven Central Repository中的类库也是可以间接下载到的。此时你可以将~/.m2/repository/中所有的内容删除掉,再在项目中执行“mvn clean install”,你将在终端中看到Maven已经开始从Nexus 的Public Repositories中下载依赖了。

OK,完成了nexus私服的搭建,项目组开发人员开发时,只要在项目的pom.xml文件中,添加如下pom.xml信息即可获取私服的jar.

如果添加其他的构件时,会先在nexus中下载好,以后才会下载到本地。以后,如果发现nexus已经存在某一jar包,则会直接从nexus下载,如果没有再去网络上下载。这就是搭建nexus的好处。

所以很有必要搭建nexus。

五、FAQ

5.1、was cached in the local repository

  5.1.1、问题描述:

    在使用maven私服仓库编译项目时,由于缺少jar包编译失败,然后上传缺失的jar包至nexus私服仓库,但是编译还失败了,

  出现错误:was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced ->   [Help 1]

  5.1.2、问题原因:

    Maven默认会使用本地缓存的库来编译工程,对于上次下载失败的库,maven会在~/.m2/repository/ / / /目录下创建xxx.lastUpdated文件

  5.1.3、解决办法:

    删除~/.m2/repository/ / / /目录下的*.lastUpdated文件,然后再次编译工程

Nexus安装配置的更多相关文章

  1. Nexus安装配置和使用

    Nexus安装配置和使用 第一步安装jdk yum install java-1.8.0-openjdk-devel 第二步下载nexus-3.12.1-01-unix.tar.gzjdk 下载地址: ...

  2. nexus 安装配置

    一.下载Nexus http://nexus.sonatype.org/downloads 我是用的版本是 nexus-2.11.4-01-bundle.tar.gz 每个版本的配置有些许差别. 二. ...

  3. Nexus 安装配置教程

    目录 为什么使用 Nexus Docker 模式安装 Nexus 使用 data volume 使用本地目录 Nexus 配置 配置 Blob Stores Nexus 使用 包下载 包上传 参考 为 ...

  4. centos安装配置和使用 Nexus

    Nexus安装配置和使用 第一步安装jdk yum install java-1.8.0-openjdk-devel 第二步下载nexus-3.12.1-01-unix.tar.gzjdk 下载地址: ...

  5. Linux下安装配置Nexus

    一.安装和运行nexus 1.下载nexus:http://www.sonatype.org/nexus/go 可选择tgz和zip格式,以及war,选择tgz或zip时不同版本可能在启动时存在一定问 ...

  6. 1.Nexus安装与配置

    1.Nexus下载下载地址:http://www.sonatype.org/nexus/go/下载后的文件:nexus-2.11.4-01-bundle.zip安装:直接解压到某个目录即可解压后,会有 ...

  7. Maven仓库Nexus的安装配置

    1.下载nexus,最新版本是nexus-2.8.0-05   参考文章 下载nexus-latest-bundle.zip文件后,并解压到  D:\nexus下 配置nexus的环境变量:先配置NE ...

  8. Linux 安装配置maven3.0 以及搭建nexus私服

    http://carvin.iteye.com/blog/785365 一.软件准备 1.apache-maven-3.0-bin.tar.gz 下载地址:http://www.apache.org/ ...

  9. linux 安装配置nexus以及maven私服应用

    ---------------------nexus---------------------- 1.编辑nexus脚本, 配置 RUN_AS_USER 参数vi /usr/local/src/nex ...

随机推荐

  1. Google C++单元测试框架GoogleTest(总)

    之前一个月都在学习googletest框架,对googletest的文档都翻译了一遍,也都发在了之前的博客里,另外其实还有一部分的文档我没有发,就是GMock的CookBook部分:https://g ...

  2. lucky 的 时光助理

    2017年的lucky小姐,厌倦了现在的工作,她觉得这些的工作对于她而言不具备挑战性,她在迷茫春节过后该如何选择, 这里是距她走出校门整整一年的时光. lucky小姐从开发走向了实施,目的是想周游这个 ...

  3. 文本处理三剑客之sed命令

    第十八章.文本处理三剑客之sed命令 目录 sed介绍 sed命令常用选项 sed常用编辑命令 sed使用示例 sed高级语法 18.1.sed简介 sed全名stream editor,流编辑器,s ...

  4. Linux下如何查看版本信息

    Linux下如何查看版本信息, 包括位数.版本信息以及CPU内核信息.CPU具体型号等等,整个CPU信息一目了然.   1.# uname -a   (Linux查看版本当前操作系统内核信息)   L ...

  5. 解决Ubuntu下Firefox+OpenJDK没有Java插件的问题

    如果是安装的OpenJDK,很遗憾它是没有libnpjp2.so的. 此时按照网上各种奇怪的方法都挣扎无效,但可以用icedtea插件来解决这个问题. icedtea的版本与本机安装的OpenJDK版 ...

  6. 【less】Bootstrap / Less 学习

    我是借助的 考拉 来编译LESS~~ http://www.openkoala.org/download.html 官网 less 提供的主要功能 1.变量个人觉得,变量是 Less 最重要的功能.举 ...

  7. Unity需要频繁登录是什么情况

    这个问题会在Unity 5.5.0p3中修复 都一样,等新版本吧

  8. click与 mousedown

    一.想做出鼠标右键 自己定义的菜单 则需要先使用 document.oncontextmenu= functions(){ event.preventDefault()//去除鼠标右键的默认格式 } ...

  9. CentOS 7.0系统安装配置步骤详解

    CentOS 7.0系统是一个很新的版本哦,很多朋友都不知道CentOS 7.0系统是怎么去安装配置的哦,因为centos7.0与以前版本是有很大的改进哦. 说明: 截止目前CentOS 7.x最新版 ...

  10. [LeetCode] Restore IP Addresses 复原IP地址

    Given a string containing only digits, restore it by returning all possible valid IP address combina ...