今天配置java 环境,安装nexus 百度了好久才安装好,所以特别写下来 分享给同样遇到问题的你。
废话不多说,直接上步骤

前置条件 :已经安装了JDK

  1. 下载nexus(http://www.sonatype.com/download-oss-sonatype) 最新版本3.0

但是这个网站在国内有时候无法访问,所以我给大家提供一个百度云的地址:

https://pan.baidu.com/s/1bRvLYQ

2.配置环境变量

首先编辑这个文件  vi ~/.bash_profile

然后增加下面的一行

export PATH=${PATH}:/Users/xiaoyuwang/java/resources/nexus-2.6.0-bundle/nexus-2.6.0-05/bin

变成如下

然后保存并退出,键入命令:wq

然后用source ~/.bash_profile让文件即时生效

3、启动nexus

进入nexus-2.2-01/bin/jsw/目录,然后根据OS的版本进入相应的目录,在linux下,运行./nexus start即启动了服务,直接运行./nexus会看到提示信息,运行./nexus console 可以以控制台方式启动nexus,方便我们观察启动时的相关工作。neuxs默认监听端口是8081,此时在浏览器中运行访问http://127.0.0.1:8081/nexus或者http://localhost:8081/nexus或者http://0.0.0.0:8081/nexus应该可以看到neuxs的界面。

如果你不会,你可以只键入nexus,系统会给出命令使用说明

Usage: /Users/xiaoyuwang/java/resources/nexus-2.6.0-bundle/nexus-2.6.0-05/bin/nexus { console | start | stop | restart | status | dump }

新搭建的neuxs环境只是一个空的仓库,需要手动和远程中心库进行同步,nexus默认是关闭远程索引下载,最重要的一件事情就是开启远程索引下载。登陆nexus系统,默认用户名密码为admin/admin123。 点击左边Views/Repositories菜单下面的Repositories,找到右边仓库列表中的三个仓库Apache Snapshots,Codehaus Snapshots和Central,然后再没有仓库的Configuration下把Download Remote Indexes修改为true。然后在这三个仓库上分别右键,选择Repari Index,这样Nexus就会去下载远程的索引文件。

新建公司的内部仓库,步骤为Repositories –> Add –> Hosted Repository,在页面的下半部分输入框中填入Repository ID和Repository Name即可,比如分别填入myrepo和 my repository,另外把Deployment Policy设置为Allow Redeploy,点击save就创建完成了。

    修改nexus仓库组

Nexus中仓库组的概念是Maven没有的,在Maven看来,不管你是hosted也好,proxy也好,或者group也好,对我都是一样的,我只管根据groupId,artifactId,version等信息向你要构件。为了方便Maven的配置,Nexus能够将多个仓库,hosted或者proxy合并成一个group,这样,Maven只需要依赖于一个group,便能使用所有该group包含的仓库的内容。

neuxs-2.2中默认自带了一个名为“Public Repositories”组,点击该组可以对他保护的仓库进行调整,把刚才建立的公司内部仓库加入其中,这样就不需要再在maven中明确指定内部仓库的地址了。同时创建一个Group ID为public-snapshots、Group Name为Public Snapshots Repositories的组,把Apache Snapshots、Codehaus Snapshots和Snapshots加入其中。

到这里neuxs的安装配置就完成了,下面介绍如何在mavne中使用自己的私服。

maven安装好默认是没有配置仓库信息,此时mavne都默认去远程的中心仓库下载所依赖的构件。既然使用了私服,就需要明确告诉maven去哪里下载构件,可以在三个地方进行配置,分别是是mavne的安装目录下的conf下的settings.xml文件,这个全局配置,再一个是在userprofile/.m2目录下的settings.xml,如果不存在该文件,可以复制conf下settings.xml,这个是针对当前用户的,还有一个是在pom.xml中指定,其只对该项目有效,三个文件的优先级是pom.xml大于.m2,.m2大于conf下。

settings.xml的配置如下:

在profiles段增加一个profile

 
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://192.168.1.68:8081/nexus/content/groups/public</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
<repository>
<id>nexus-snapshots</id>
<name>local private nexus</name>
<url>http://192.168.1.68:8081/nexus/content/groups/public-snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://192.168.1.68:8081/nexus/content/groups/public</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</pluginRepository>
<pluginRepository>
<id>nexus-snapshots</id>
<name>local private nexus</name>
<url>http://192.168.1.68:8081/nexus/content/groups/public-snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
 

上述的id,name可以根据自己的喜好来定义,保证多个repository的id不重复即可,主要是url的配置,可以在nexus的repositories列表中找到对应的url,就是repositories的Repository Path,刚才我们已经在neuxs中定于了仓库组,这里就取对应组的Repository Path信息即可。

另外,仓库是两种主要构件的家。第一种构件被用作其它构件的依赖。这是中央仓库中存储的大部分构件类型。另外一种构件类型是插件。如果不配置pluginRepositories,那么执行maven动作时,还是会看到去远程中心库下载需要的插件构件,所以这里一定要加上这个。

在settings.xml中指使配置了profile还不行,需要激活它,在activeProfiles段,增加如下配置:

<activeProfile>nexus</activeProfile>

此处activeProfile中的内容就上面定义profile的id。
    pom.xml配置如下:

<repositories>
<repository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://192.168.1.68:8081/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>nexus-snapshots</id>
<name>local private nexus</name>
<url>http://192.168.1.68:8081/nexus/content/groups/public-snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://192.168.1.68:8081/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>nexus-snapshots</id>
<name>local private nexus</name>
<url>http://192.168.1.68:8081/nexus/content/groups/public-snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

  

 

其中id,name都无所谓,关键不能把url弄错。

有了上述配置,当在项目执行maven操作时,如果本地库中没有依赖的构件,maven会去私服下载,如果私服也没有,私服会去远程中心库下载,同时会在私服的本地缓存,这样如果第二个人再要用到这个构件,私服就直接提供下载。

参考资料:

http://blog.csdn.net/sxdtzhaoxinguo/article/details/46895013

Mac 安装配置nexus2.6 搭建Maven的中央仓库的更多相关文章

  1. Nexus搭建Maven私服中央仓库

    一.概述 1.概要 现在的项目基本都是用Maven来管理工程,这样一来在公司内容搭建一个私服就非常有必要了,这样一来可以管理公司内部用的JAR包,也可以管理第三方的各种JAR来,以免每次都要从外网的仓 ...

  2. mac安装配置mysql

    目录 mac安装配置mysql 1.mysql的安装 2.设置root用户的密码 3.分别执行一下命令 4.配置mysql环境变量 mac安装配置mysql 1.mysql的安装 ​ 安装过程十分简单 ...

  3. SpringMVC框架入门配置 IDEA下搭建Maven项目(zz)

    SpringMVC框架入门配置 IDEA下搭建Maven项目 这个不错哦 http://www.cnblogs.com/qixiaoyizhan/p/5819392.html

  4. mac 安装配置使用 mongoldb

    mac 安装配置使用 mongoldb 安装和配置 brew install mongos brew install mongo # 密码就是用户的密码 # 配置数据文件 //如果不配置会出现错误62 ...

  5. maven替换中央仓库,阿里云镜像下载及自定义本地仓库位置

    maven替换中央仓库- 阿里云 在国内访问Maven仓库,下载速度太慢.下面是将中央仓库替换成阿里云的中央仓库的方法.国内还有其他的公共仓库,自己选择.  在你下载的maven版本-conf-set ...

  6. Android Studio安装配置、环境搭建详细步骤及基本使用

    前言 Android Studio的安装配置及使用篇终于来啦~ 废话不多说,以下针对JDK正确安装(及其环境变量配置完毕,即Java开发环境下).Android Studio的安装,配置,以及创建工程 ...

  7. SpringMVC框架入门配置 IDEA下搭建Maven项目

    初衷:本人初学SpringMVC的时候遇到各种稀奇古怪的问题,网上各种技术论坛上的帖子又参差不齐,难以一步到位达到配置好的效果,这里我将我配置的总结写到这里供大家初学SpringMVC的同僚们共同学习 ...

  8. Mac 安装配置Mysql

    Mac下安装配置Mysql By 白熊花田(http://blog.csdn.net/whiterbear) 转载需注明出处,谢谢. 下载安装 去官网下载Community版本号的mysql安装文件. ...

  9. [转]SpringMVC框架入门配置 IDEA下搭建Maven项目

    初衷:本人初学SpringMVC的时候遇到各种稀奇古怪的问题,网上各种技术论坛上的帖子又参差不齐,难以一步到位达到配置好的效果,这里我将我配置的总结写到这里供大家初学SpringMVC的同僚们共同学习 ...

随机推荐

  1. Android:Camera

    Android Camera开发 Android手机关于Camera的使用,一是拍照,二是摄像,由于Android提供了强大的组件功能,为此对于在Android手机系统上进行Camera的开发,我们可 ...

  2. 560. Subarray Sum Equals K

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  3. OneNET麒麟座应用开发之十:空气质量数据监测站项目总结

    大气质量数据监测站用于测试空气质量监测及数据采集,实现野外或者室内空气质量的检测. 1.项目概述 本项目是一个定制项目,要求采集大气的压力.温度.湿度.PM25.位置等数据并上传到指定的后台服务器.但 ...

  4. python与redis

    1.什么是redis Redis 是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset ...

  5. 完全背包记录路径poj1787 好题

    这题有点多重背包的感觉,但还是用完全背包解决,dp[j]表示凑到j元钱时的最大硬币数,pre[j]是前驱,used[j]是凑到j时第i种硬币的用量 △回溯答案时i-pre[i]就是硬币价值 #incl ...

  6. 步步为营-64-进程&线程

    1 进程 using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; us ...

  7. 《Kafka技术内幕》学习笔记

    第一章 Kafka入门 1.1 Kafka流式数据平台 Kafka作为流式数据平台的特点: 消息系统:两种消息模型:队列和发布订阅. 队列模型:将处理工作平均分给消费组中的消费者成员. 发布订阅模型: ...

  8. 转载 c++指针 指针入门

    这是一篇我所见过的关于指针的最好的入门级文章,它可使初学者在很短的时间内掌握复杂的指针操作.虽然,现在的Java.C#等语言已经取消了指针,但作为一个C++程序员,指针的直接操作内存,在数据操作方面有 ...

  9. Codeforces 1041F Ray in the tube (看题解)

    Ray in the tube 感觉是套路题.. 如果确定一个差值x我们如何取确定答案呢, 我们把a[ i ] -> a[ i ] % (2 * x), 把b[ i ] -> (b[ i ...

  10. split应用

    /* input:"5 35 53 2 3" output:"2 3 5 35 53" */ public class RegexDemo4 { public ...