前面已经说过了,咱们使用Maven的使用,若是须要导入相对应的jar包,Maven首先会在咱们的本地仓库中寻找—>私有仓库—>中心仓库…css
然而,咱们的本地仓库经常没有想要的jar包的,而常常去中心仓库下载这就很是浪费时间和资源了…所以咱们通常都有一个私有仓库…web
另外有些公司都不提供外网给项目组人员,所以就不能使用maven访问远程的仓库地址,因此颇有必要在局域网里找一台有外网权限的机器,搭建nexus私服,而后开发人员连到这台私服上,这样的话就能够经过这台搭建了nexus私服的电脑访问maven的远程仓库浏览器
咱们使用的是nexus框架来搭建私服,它属于sonatype 机构的开源框架,用该框架架设maven 私有服务器缓存
Nexus环境搭建tomcat
tomcat会自动解析war包,而后就自动下载插件…
服务器
访问该项目,进到首页markdown
登录…
oracle
每一个仓库的做用:app
仓库组是一个虚拟的概念,就是经过对实体仓库(proxy、hosted)进行聚合, 对外暴露一个统一的地址这里要注意的是,放到左边的仓库,才是会被聚合的仓库框架
仓库组的配置顺序:
直接经过网站上传,把桌面上的pig-0.12.1.jar上传到私有服务器中
再次查看的时候,已经上传上去了
在pom.xml文件配置私服的路径、组id、版本等等
<!-- 假如没有私服 ,则 本地仓库找不到,则访问中心仓库 假若有私服 :访问顺序 首先访问本地仓库 本地仓库没有,则访问私服仓库 私服仓库也没有,则访问中心仓库 --> <!-- 加载的是 第三方项目使用的jar包 --> <repositories> <repository> <snapshots> <enabled>true</enabled> </snapshots> <id>public</id> <name>public</name> <url>http://localhost:8080/nexus-2.6.2/content/groups/public/</url> </repository> </repositories> <!-- 加载的是maven生命周期插件的jar包 --> <pluginRepositories> <pluginRepository> <releases> <updatePolicy>never</updatePolicy> </releases> <snapshots> <enabled>true</enabled> </snapshots> <id>public</id> <name>public</name> <url>http://127.0.0.1:8080/nexus-2.6.2/content/groups/public/</url> </pluginRepository> </pluginRepositories>
在本地仓库中也把私服的jar包下载下来了
server的配置能够在Maven的settings.xml中写上
<!-- 分销管理 ,把jar包发布到私服中 -->
<!-- 配置服务器-->
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
值得注意的是:你得留意你用的是哪一个Maven,是你本身下载的Maven仍是使用Idea集成的Maven,若是没有配置的话,那么就会出现401错误。
<distributionManagement> <!-- 发布到 快照版本的仓库,即 测试版本仓库 --> <snapshotRepository> <id>snapshots</id> <url>http://127.0.0.1:8080/nexus-2.6.2/content/repositories/snapshots/</url> </snapshotRepository> <!-- 发布到 发行版本的仓库中,也能够发布到3rd party 仓库 --> <repository> <id>releases</id> <url>http://127.0.0.1:8080/nexus-2.6.2/content/repositories/releases/</url> </repository>
再次查看仓库组