若是构建的Maven项目本地仓库没有对应的依赖包,那么就会去Nexus私服去下载, 那么若是Nexus私服也没有此依赖包,就回去远程中央仓库下载依赖, Nexus私服下载成功后再下载至本地Maven库供项目引用web
myeclipse中集成了maven,若是它链接的是中央仓库,不是私有库,若是没有配置本地库,下载的依赖默认是在~/.me/repository
文件加下面,若是配置了本地库,就会下载到自定义的本地库中,好比~/apache-maven-3.1.0/.me/repository
apache
环境:CentOS 6.6 Final、JDK七、Sonatype Nexus、Maven
IP:192.168.4.221
root 用户操做
前提:已安装 JDK7 并配置好了环境变量
一、下载最新版 Nexus(本教程使用的是:nexus-2.11.2-03-bundle.tar.gz),下载地址:
http://www.sonatype.org/nexus/go/浏览器
# wget https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.11.2- 03-bundle.tar.gz
二、解压架构
# mkdir nexus # tar -zxvf nexus-2.11.2-03-bundle.tar.gz -C nexus # cd nexus # ls nexus-2.11.2-03 sonatype-work //(一个 nexus 服务,一个私有库目录)
ps:
进入nexus-2.11.2-03下的lib服务发现有大量的jetty包,说明是经过jetty运行服务的
三、编辑 Nexus 的 nexus.properties 文件,配置端口和 work 目录信息(保留默认)oracle
# cd nexus-2.11.2-03 # ls bin conf lib LICENSE.txt logs nexus NOTICE.txt tmp
查看目录结构,jetty 运行app
# cd conf # vi nexus.properties # Jetty section //jetty的端口 application-port=8081 //容许全部的ip都能访问 application-host=0.0.0.0 //app位置在${bundleBasedir}/nexus nexus-webapp=${bundleBasedir}/nexus //项目访问的名字是nexus nexus-webapp-context-path=/nexus # Nexus section //工做目录,即上面的私有库目录,里面目前什么都没有 nexus-work=${bundleBasedir}/../sonatype-work/nexus runtime=${bundleBasedir}/nexus/WEB-INF
四、编辑 nexus 脚本, 配置 RUN_AS_USER 参数eclipse
# vi /root/nexus/nexus-2.11.2-03/bin/nexus #RUN_AS_USER= 改成: RUN_AS_USER=root
基于 Dubbo 的分布式系统架构视频教程 做者:吴水成,840765167@qq.com,wu-sc@foxmail.com
五、防火墙中打开 8081 端口webapp
# vi /etc/sysconfig/iptables
添加:maven
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8081 -j ACCEPT
保存后重启防火墙tcp
# service iptables restart
六、启动 nexus
# /root/nexus/nexus-2.11.2-03/bin/nexus start **************************************** WARNING - NOT RECOMMENDED TO RUN AS ROOT **************************************** Starting Nexus OSS... Started Nexus OSS.
七、浏览器中打开:http://192.168.4.221:8081/nexus/
八、登陆,默认用户名 admin,默认密码 admin123:
到此,Nexus 已安装完成,接下来是 Nexus 的配置
一、菜单 Administration/Server 配置邮箱服务地址(若是忘记密码,能够经过该邮箱找回密 码)
给用户配置邮箱地址,方便忘记密码时找回:
点击Test SMTP setting能够测试邮箱是否能设置,点击validate,点击最后的保存后会发送邮件。
有三个用户,管理员用户(admin)、部署用户(deployment)、anoymous(有道上查的是匿名的,自我理解是游客吧,嘿嘿)
点击邮箱可以修改用户的邮箱==>save
以后退出后再次进入nexus==>输入username和e-mail(刚刚新设置的email)便可从新登陆
用户修改密码
二、仓库类型
group 仓库组(public repository):Nexus 经过仓库组的概念统一管理多个仓库,这样咱们在项目中直接请求仓库组便可请求到仓库组管理的多个仓库;
意思就是上图的public repository包含里下面的全部的仓库
hosted 宿主仓库:主要用于发布内部项目构件或第三方的项目构件(如购买商业的构件)以及没法从公共仓库获取的构件(如 oracle 的 JDBC 驱动)
proxy 代理仓库:代理公共的远程仓库; (上面的三个均可以理解为中央仓库)
virtual 虚拟仓库:用于适配 Maven 1; (基本不用)
通常用到的仓库种类是 hosted、proxy
Hosted 仓库经常使用类型说明:
releases 内部的模块中 release 模块的发布仓库,就是咱们本身的项目给了一个version ,而后经过deploy就会发布到私有仓库的releases库中
snapshots 发布内部的 SNAPSHOT 模块的仓库,好比项目的verison是1.0-SNAPSHOTS
上面两个能够理解为就是咱们本身写的项目install可以install到本地供其余项目访问的模块
三、设置 proxy 代理仓库(Apache Snapshots/Central/Codehaus Snapshots)准许远程下载, 如:
注意远程仓库一共有三个,都要进行设置。
若是不设置就不能调动中央库,若是点击了保存,看左侧列表中的Scheduled Task ,发现有任务正在运行,就是去下载中央库的索引
下载完以后点击Brows Index > Fefresh>点击下面的文件加,会出现中央库各类文件的索引
四、Maven 本地库的安装与配置(请看参考视频的操做) 环境变量、setting.xml
本地库链接私有库==>私有库代理远程仓库
下载一个maven的解压包==>加压==>进入conf目录==>新建一个settins.xml,名字自定义,好比settings_edu.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"> //配置本地库的目录,若是不配置的话,Myeclipse的默认下载路径就是~/.m2/repository <localRepository>E:/apache-maven-3.1.0/.m2/repository</localRepository> <interactiveMode>true</interactiveMode> <offline>false</offline> <pluginGroups> <pluginGroup>org.mortbay.jetty</pluginGroup> <pluginGroup>org.jenkins-ci.tools</pluginGroup> </pluginGroups> <!--配置权限,使用默认用户--> //设置使用哪一个用户链接本地库 <servers> <server> <id>nexus-releases</id> <username>deployment</username> <password>deployment123</password> </server> <server> <id>nexus-snapshots</id> <username>deployment</username> <password>deployment123</password> </server> </servers> <mirrors> </mirrors> <profiles> <profile> <id>edu</id> //配置jdk版本 <activation> <activeByDefault>false</activeByDefault> <jdk>1.6</jdk> </activation> <repositories> //<!-- 私有库地址,配置私有库--> <repository> <id>nexus</id> //这里了是仓库组的地址,地址的具体内容在上面介绍的客户端仓库类型的图片中可以找到 <url>http://192.168.4.221:8081/nexus/content/groups/public/</url> //release被snapshaots都设置成生效。 <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> //<!--插件库地址-->,插件库也须要从仓库下载 //这里也经过私服代理 <pluginRepository> <id>nexus</id> <url>http://192.168.4.221:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> //<!--激活profile--> //注意上面profile的配置中<id>edu</id>,id是edu,须要在这里激活一下 <activeProfiles> <activeProfile>edu</activeProfile> </activeProfiles> </settings>
五、MyEclipse 中的 Maven 配置(请看参考视频的操做)
上面修改了本身maven的本地配置文件,这里须要在eclipse中进行配置:
打开配置==>MyEclipse==>Maven4==>MyEclipse==>Installations==>edit ----配置本身maven的目录
打开配置==>MyEclipse==>Maven4==>MyEclipse==>User Settings==>Browse指向刚才上面的配置文件==>update setting ----修改默认的配置文件settings.xml为新的settings_edu.xml(名字随具体状况而定,上面的xml命名是什么这里就是什么)
六、项目的构建与发布演示(请看参考视频的操做)
修改 common-parent 中的 pom.xml 中的私有库地址,这个项目中原来的私有库地址是做者本身的,因此应该修改成刚刚本身从新搭建的私有库地址(没有前几节的背景,能够忽略这步)
演示如何把common-parent项目部署到私有库上,eclipse中打开common-parent的pom.xml,右键==>运行==>Maven build==>Browse Workspace==>选择common-parent项目==>Goals:clean install deploy(install安装到本地库,deploy发布到私有库)>Profiles:pom.xml>点击run
而后回到客户端,点击Snapshots的repositories==>点击下面的refresh==>发现已经有了刚刚上传到私有库的项目,可是这里不是一个jar包,只是一个pom,一个maven工程的附文件,由于当前的pom文件pom,若是jar的话就会上传jar包==>右侧有别人引用这个项目所须要输入的内容
这里注意但愿发布到Snapshots仍是Realese经过本身pom文件的配置进行修改,就会发布到对应的仓库中
若是common-core项目依赖common-parent项目,但是common-parent项目已经更新了不少版本,如何在本身的项目中更新引用呢? 点common-core的pom.xml,>右击>run as ==>maven isntall便可
七、上传第三方包操做演示
进入客户端==>点击3rd party==>Artifact Upload==>GAV Definition 选择GAV Parameters==>下面自行填写group id、artifact、version、pacakging选择jar包==>点击select Artifact(s) to Upload==>选中jar包==>点击add Artifact==>点击upload Artifacts
点击3rd party的Browse Index > 点击refresh ,发现已经有了jar包>右侧有引用的pependency的写法。