maven的仓库分为本地仓库,远程仓库和私服仓库。
私服仓库通常是公司内部私有的,内部进行维护的。公司员工链接私服,从私服中下载jar,或者将自身的jar传到私服上。私服还能够从中央仓库下载jar,当私服中没用jar的时候,就会从中央仓库下载。
linux
下载 Nexus,下载地址:http://www.sonatype.org/nexus/archived/ 。
能够选择zip和tar,分别对应windows和linux。web
将下载的zip解压,使用cmd进入bin目录,执行命令:windows
nexus.bat install
执行命令:app
nexus.bat uninstall
一、cmd进入目录,执行命令webapp
nexus.bat start
二、在服务中找到nexus,右键启动maven
查看 nexus 的配置文件conf/nexus.properties
application-port=8081 # nexus 的访问端口配置
application-host=0.0.0.0 # nexus 主机监听配置(不用修改)
nexus-webapp=${bundleBasedir}/nexus # nexus 工程目录
nexus-webapp-context-path=/nexus # nexus 的 web 访问路径
nexus-work=${bundleBasedir}/../sonatype-work/nexus # nexus 仓库目录
runtime=${bundleBasedir}/nexus/WEB-INF # nexus 运行程序目录url
http://localhost:8081/nexus/
点击右上角log in,输入用户名和密码
默认是admin/admin123
登陆完毕
插件
在maven的setting.xml中配置code
<server> <id>releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>admin123</password> </server>
配置项目的pom文件server
<distributionManagement> <repository> <id>releases</id> <url>http://localhost:8081/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>snapshots</id> <url>http://localhost:8081/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement>
使用deploy命令便可将jar发布到私服,发布工程中的version,若是以snapshot结尾,则能够发布到快照仓库,若是以release结尾,则能够发布到releases版本。
在setting中配置私服仓库
<profile> <!--profile 的 id--> <id>dev</id> <repositories> <repository> <!--仓库 id,repositories 能够配置多个仓库,保证 id 不重复--> <id>nexus</id> <!--仓库地址,即 nexus 仓库组的地址--> <url>http://localhost:8081/nexus/content/groups/public/</url> <!--是否下载 releases 构件--> <releases> <enabled>true</enabled> </releases> <!--是否下载 snapshots 构件--> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <!-- 插件仓库,maven 的运行依赖插件,也须要从私服下载插件 --> <pluginRepository> <!-- 插件仓库的 id 不容许重复,若是重复后边配置会覆盖前边 --> <id>public</id> <name>Public Repositories</name> <url>http://localhost:8081/nexus/content/groups/public/</url> </pluginRepository> </pluginRepositories> </profile>
激活
<activeProfiles> <activeProfile>dev</activeProfile> </activeProfiles>