Nexus本地私服
2017-10-28 本文已影响8人
imacoder
工作原理

用户先访问私服,如果私服上存在jar包,则直接返回给用户;如果私服上不存在,则去远程仓库下载,默认apache maven。找到后先下载到私服,再由私服返回给用户。
部署Nexus
nexus实现了maven的管理平台,它是一个war包,可以部署到tomcat中
复制nexus-2.1.2.war到tomcat/webapps下,改名为nexus.war(这样访问无需加后面的版本号),修改tomcat端口为8010,防止和其他tomcat启动相冲突,启动tomcat。
访问:http://localhost:8010/nexus,能访问,搭建nexus成功!

设置镜像访问私服
全局设置:C:\Users\Administrator\.m2\settings.xml

项目直接访问私服
pom.xml最后配置

改变仓库
默认maven是连接远程仓库,修改用户连接到本地仓库,当本地仓库没有jar包时,会自动连接到远程仓库,先下载到本地仓库,然后返回给用户。
1)修改C:\Users\Administrator\.m2\setting.xml中配置,指向nexus。
配置权限:

配置镜像:

配置profile:

激活配置:

2)项目下执行mvn test,断开外网,看能否下载jar包
3)执行mvn clean
mvn install -X(必须大写X)
mvn deploy
登录http://localhost:8010/nexus
如deploy无错,查看Repositories/Snapshots就可以看到项目。
权限错误
如报权限错误,在setting.xml中加入下面内容:
