一、下载最新版本的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. iOS10 适配问题-Xcode8

    前段时间升级了Xcode8,整体来说对OC的影响不大,但是还是跳一个坑,消耗了不少时间.这里总结下遇到的适配问题. 1.权限问题 Xcode8 访问相机.相册等需要权限的地方崩溃 解决办法: 在使用私 ...

  2. JAVA并发编程J.U.C学习总结

    前言 学习了一段时间J.U.C,打算做个小结,个人感觉总结还是非常重要,要不然总感觉知识点零零散散的. 有错误也欢迎指正,大家共同进步: 另外,转载请注明链接,写篇文章不容易啊,http://www. ...

  3. MySQL高可用方案

    高可用架构对于互联网服务基本是标配,无论是应用服务还是数据库服务都需要做到高可用.虽然互联网服务号称7*24小时不间断服务,但多多少少有一些时候服务不可用,比如某些时候网页打不开,百度不能搜索或者无法 ...

  4. Hive-0.x.x - Enviornment Setup

    All Hadoop sub-projects such as Hive, Pig, and HBase support Linux operating system. Therefore, you ...

  5. Surface在C++层的创建源码解析

    Surface在C++层的创建源码解析 源码为:android4.4.4 1.创建SurfaceComposerClient绘图客户端 // create a client to surfacefli ...

  6. java nio系列文章

    java nio系列教程 基于NIO的Client/Server程序实践 (推荐) java nio与并发编程相关电子书籍   (访问密码 48dd) 理解NIO nio学习记录 图解ByteBuff ...

  7. 【码在江湖】前端少侠的json故事(中)ng的json

    ng的json 正所谓"人在江湖,身不由己",在开发之路上前端少侠dk遇到过种种困难,尤其在与后端进行数据对接的时候,不得不逼迫自己以极快的速度去学习和掌握一些奇招怪式,正当他以为 ...

  8. SQL必知必会 14-22(完)

    博主依然不想打字,又向你仍来了一堆代码... 13(续) 在SELECT中用COUNT()以及联合 mysql> SELECT customers.cust_id,COUNT(orders.or ...

  9. 必杀技———SQL基础整理系列(一)

    SQL(Structured Query Language)——结构化查询语言 SQL语言的组成部分 数据定义语言 (DDL:Data Definition Language) 负责数据结构定义与数据 ...

  10. 揭开C++类中虚表的“神秘面纱”

    C++类中的虚表结构是C++对象模型中一个重要的知识点,这里咱们就来深入分析下虚表的在内存中的结构. C++一个类中有虚函数的话就会有一个虚表指针,其指向对应的虚表,一般一个类只会有一个虚表,每个虚表 ...