maven搭建nexus私服
2016-12-17 16:55
369 查看
一、搭建私服的好处
传统的maven项目依赖包都是从maven中央仓库中直接获取的,如果一个公司有多台开发机,很有可能会出现多次重复下载同一个jar包,而且每一次下载都需要联网到中央仓库去寻找,这样会严重影响带宽,而且效率也很低。
搭建私服的原理就是拿一台计算机来做代理服务器,这台代理服务器直接获取中央仓库的jar包,当某台开发机需要相关的jar包时,就配置从这台代理服务器拿,如果代理服务器已经有这个jar就直接提供给开发机,没有再去中央仓库下载。
由于私服和开发机是位于同一个内网的,如果私服已经有开发机需要的jar包,那么速度肯定会比直接去中央仓库下载快的多。
二、搭建私服需要的配置
1.下载nexus2.1.2私服(web工程,nexus2.1.2.war),拷贝到本地服务器webapps下,启动服务器。
打开浏览器输入http://localhost:8080/nexus-2.1.2,看到如下界面表示部署成功。
2.下载nexus2.1.2 maven依赖的索引文件(完整的索引包含nexus所有仓库的索引,这里只需要中央仓库的索引就足够[central-ctx])
进入${user.home}\sonatype-work\nexus\indexer目录,将中央仓库的索引文件拷贝到里面替换。重启nexus私服,使用admin/admin123登录,点击repositories选中central(中央仓库)的Browe Index,可以看到下面有很多根据索引获得的中央仓库依赖坐标,通过点击需要的jar文件,就可以看到依赖的pom配置。
3.配置maven的settings文件,并拷贝一份到仓库同级目录
<?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">
<localRepository>D:\PATH\maven_repository\repository</localRepository>
<servers>
<server>
<id> releases </id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id> snapshots </id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<!-- *代表所有依赖都从nexus私服http://localhost:8080/nexus-2.1.2/content/groups/public下载(type是group那个仓库,包含其它仓库的合集) -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8080/nexus-2.1.2/content/groups/public</url>
</mirror>
</mirrors>
<!-- 配置mirror的过滤策略 -->
<profiles>
<profile>
<id>nexus</id>
<repositories>
<!--表示依赖都从central(中央仓库)下载,地址是?,url的值可以随意写,因为mirror中已经配置了地址
releases true,代表可以从中央仓库中下载发布版本的依赖
snapshots true,代表可以从中央仓库中下载测试版本(未发布)的依赖
-->
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<!--表示maven插件都从central(中央仓库)下载,地址是?,url的值可以随意写,因为mirror中已经配置了地址
releases true,代表可以从中央仓库中下载发布版本的插件
snapshots true,代表可以从中央仓库中下载测试版本(未发布)的插件
-->
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!-- 表示启动哪个profile -->
<activeProfiles>
<!--profile配置的名称(id) -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
4.pom.xml中配置自己的项目发布到私服的哪个仓库地址(一般配置在父项目中,子项目继承即可。)
<distributionManagement>
<repository>
<id>releases</id>
<name>Internal Releases</name>
<url>http://localhost:8080/nexus-2.1.2/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Internal Snapshots</name>
<url>http://localhost:8080/nexus-2.1.2/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
这里项目是发布版还是测试版通过项目pom.xml配置项目的版本后缀决定,如
<!-- 项目版本号 -->
<version>0.0.1-SNAPSHOT</version>
指的就是测试版,就会上传到snapshotRepository标签中的url地址。
上传项目只需要使用 mvn deploy即可(myeclipse中只需要 deploy)
传统的maven项目依赖包都是从maven中央仓库中直接获取的,如果一个公司有多台开发机,很有可能会出现多次重复下载同一个jar包,而且每一次下载都需要联网到中央仓库去寻找,这样会严重影响带宽,而且效率也很低。
搭建私服的原理就是拿一台计算机来做代理服务器,这台代理服务器直接获取中央仓库的jar包,当某台开发机需要相关的jar包时,就配置从这台代理服务器拿,如果代理服务器已经有这个jar就直接提供给开发机,没有再去中央仓库下载。
由于私服和开发机是位于同一个内网的,如果私服已经有开发机需要的jar包,那么速度肯定会比直接去中央仓库下载快的多。
二、搭建私服需要的配置
1.下载nexus2.1.2私服(web工程,nexus2.1.2.war),拷贝到本地服务器webapps下,启动服务器。
打开浏览器输入http://localhost:8080/nexus-2.1.2,看到如下界面表示部署成功。
2.下载nexus2.1.2 maven依赖的索引文件(完整的索引包含nexus所有仓库的索引,这里只需要中央仓库的索引就足够[central-ctx])
进入${user.home}\sonatype-work\nexus\indexer目录,将中央仓库的索引文件拷贝到里面替换。重启nexus私服,使用admin/admin123登录,点击repositories选中central(中央仓库)的Browe Index,可以看到下面有很多根据索引获得的中央仓库依赖坐标,通过点击需要的jar文件,就可以看到依赖的pom配置。
3.配置maven的settings文件,并拷贝一份到仓库同级目录
<?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">
<localRepository>D:\PATH\maven_repository\repository</localRepository>
<servers>
<server>
<id> releases </id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id> snapshots </id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<!-- *代表所有依赖都从nexus私服http://localhost:8080/nexus-2.1.2/content/groups/public下载(type是group那个仓库,包含其它仓库的合集) -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8080/nexus-2.1.2/content/groups/public</url>
</mirror>
</mirrors>
<!-- 配置mirror的过滤策略 -->
<profiles>
<profile>
<id>nexus</id>
<repositories>
<!--表示依赖都从central(中央仓库)下载,地址是?,url的值可以随意写,因为mirror中已经配置了地址
releases true,代表可以从中央仓库中下载发布版本的依赖
snapshots true,代表可以从中央仓库中下载测试版本(未发布)的依赖
-->
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<!--表示maven插件都从central(中央仓库)下载,地址是?,url的值可以随意写,因为mirror中已经配置了地址
releases true,代表可以从中央仓库中下载发布版本的插件
snapshots true,代表可以从中央仓库中下载测试版本(未发布)的插件
-->
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!-- 表示启动哪个profile -->
<activeProfiles>
<!--profile配置的名称(id) -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
4.pom.xml中配置自己的项目发布到私服的哪个仓库地址(一般配置在父项目中,子项目继承即可。)
<distributionManagement>
<repository>
<id>releases</id>
<name>Internal Releases</name>
<url>http://localhost:8080/nexus-2.1.2/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Internal Snapshots</name>
<url>http://localhost:8080/nexus-2.1.2/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
这里项目是发布版还是测试版通过项目pom.xml配置项目的版本后缀决定,如
<!-- 项目版本号 -->
<version>0.0.1-SNAPSHOT</version>
指的就是测试版,就会上传到snapshotRepository标签中的url地址。
上传项目只需要使用 mvn deploy即可(myeclipse中只需要 deploy)
相关文章推荐
- 使用nexus搭建maven私服教程详解
- 使用Nexus搭建Maven私服
- Centos7 搭建最新 Nexus3 Maven 私服
- 使用nexus搭建Maven私服
- 用nexus搭建maven私服 配置
- 使用Nexus搭建Maven私服
- Sonatype Nexus 搭建Maven 私服
- 使用Nexus搭建Maven私服
- Ubuntu下使用Nexus搭建Maven私服
- Linux下搭建maven-nexus私服仓库
- 最新maven 3.3.1+nexus 2.11.2+eclipse4.4+tomcat 8.0私服搭建到使用部署全过程————————by 耗子
- Maven学习总结(9)——使用Nexus搭建Maven私服
- 使用nexus搭建Maven私服
- 搭建Maven私服(Nexus)
- Maven入门,Maven项目的创建,nexus 2.x搭建私服以及Maven多模块项目创建
- centos7搭建nexus maven私服
- Maven系列二:利用Nexus搭建私服
- 使用Nexus搭建Maven私服
- maven教程四之使用Nexus搭建Maven私服
- Linux 安装配置maven3.0 以及搭建nexus私服