私服:仓库管理器也叫私服或代理仓库。

仓库管理器有两个服务目的:
1.它的角色是一个高度可配置的介于你的组织与公开Maven仓库之间的代理;
2.它为你的组织提供了一个可部署你组织内部生成的构件的地方。

本人云maven私服:http://193.112.71.121:8081/nexus

##安装nexus
下载地址:https://www.sonatype.com/download-oss-sonatype
链接:https://pan.baidu.com/s/1s1XZyKY0LV29yvGFxnALmQ
提取码:o21f

解压到非中文路径下

android搭建maven私服 如何搭建maven服务器_上传

在bin目录下使用cmd命令执行 nexus install

要使用管理员身份运行cmd,不然会被拒绝访问

我已经安装了所以出现已存在

android搭建maven私服 如何搭建maven服务器_上传_02

启动服务

同样在bin目录下输入nexus start

android搭建maven私服 如何搭建maven服务器_maven_03

如果没有关闭,启动会出现下提示一直在运行

android搭建maven私服 如何搭建maven服务器_android搭建maven私服_04

###测试访问
安装在本地的默认地址:http://localhost:8081/nexus
默认 账号: admin 密码: admin123

它默认端口号为8081,那么如何修改它的端口了?

android搭建maven私服 如何搭建maven服务器_maven_05


android搭建maven私服 如何搭建maven服务器_jar包_06

android搭建maven私服 如何搭建maven服务器_jar包_07

nexus介绍

Nexus是一个强大的Maven仓库管理器, 它极大地简化了自己内部仓库的维护和外部仓库的访问。 利用Nexus你可以只在一个地方就能够完全控制访问和部署在你所维护仓库中的每个Artifact。Nexus是一套“开箱即用”的系统不需要数据库,它使用文件系统加Lucene来组织数据。 Nexus使用ExtJS来开发界面,利用Restlet来提供完整的REST APIs,通过m2eclipse与Eclipse集成使用。 Nexus支持WebDAV与LDAP安全身份认证。

android搭建maven私服 如何搭建maven服务器_jar包_08

###仓库类型

android搭建maven私服 如何搭建maven服务器_上传_09

默认仓库介绍

android搭建maven私服 如何搭建maven服务器_maven_10

nexus配置

###开启远程索引
方式一:

新搭建的neuxs环境只是一个空的仓库,需要手动和远程中心库进行同步,nexus默认是关闭远程索引下载,最重要的一件事情就是开启远程索引下载。登陆nexus系统,默认用户名密码为admin/admin123。点击左边Administration菜单下面的Repositories,找到右边仓库列表中的二个仓库Apache Snapshots,Maven Central,然后再没有仓库的configuration下把Download Remote Indexes修改为true。如下图

android搭建maven私服 如何搭建maven服务器_android搭建maven私服_11

然后在Apache Snapshots,Codehaus Snapshots和Maven Central这三个仓库上分别右键,选择Repari Index,这样Nexus就会去下载远程的索引文件。

android搭建maven私服 如何搭建maven服务器_maven_12

这样设置以后, Nexus会自动从远程中央仓库下载索引文件, 为了检验索引文件自动下载是否生效,切换到Browse Index
这种方式需要从远程站点下载,速度相对比较慢。

方式二:

  直接给大家提供下载好的仓库索引文件,直接覆盖就可以了。

链接:https://pan.baidu.com/s/1_Rofajqlt4LaI8B_l9sUCg

提取码:616l

步骤:

1.先停止nexus服务

android搭建maven私服 如何搭建maven服务器_maven_13

2.解压

3.删除该目录下所有文件%Nexus_Home%\sonatype-work\nexus\indexer\central-ctx。然后将解压的文件复制进去

android搭建maven私服 如何搭建maven服务器_上传_14

  1. 重启服务即可。

android搭建maven私服 如何搭建maven服务器_jar包_15

这样后面就不用再去官网查找了!!!

##创建宿主仓库
新建公司的内部仓库:
步骤为Repositories –> Add –> Hosted Repository,在页面的下半部分输入框中填入Repository ID和Repository Name即可,比如分别填入
myId 和 myRepostiory,另外把Deployment Policy设置为Allow Redeploy,点击save就创建完成了。

android搭建maven私服 如何搭建maven服务器_上传_16

android搭建maven私服 如何搭建maven服务器_maven_17

android搭建maven私服 如何搭建maven服务器_jar包_18

##私服中配置代理

 虽然搭建了私服,但是如果私服中没有我们需要的jar包,它还是会去中央仓库去下载,这是速度同样很慢,这时我们可以在nexus中添加阿里的代理服务器。步骤如下:

android搭建maven私服 如何搭建maven服务器_maven_19

远程地址是:http://maven.aliyun.com/nexus/content/groups/public/

在把该代理仓库添加到group中

android搭建maven私服 如何搭建maven服务器_android搭建maven私服_20

如此:使用的时候就会先通过阿里镜像代理去下载

##创建Nexus仓库组

android搭建maven私服 如何搭建maven服务器_jar包_21

##如何在maven中使用自己的私服。

在setting.xml文件中的servers节点中添加

android搭建maven私服 如何搭建maven服务器_maven_22

<server>
     <id>nexus</id>
     <username>admin</username>
     <password>admin123</password>
 </server>

其次在mirrors节点中配置:

<mirror>
  <id>nexus</id>
  <mirrorOf>*</mirrorOf>
  <name>Human Readable Name for this Mirror.</name>
  <url>http://localhost:8081/nexus/content/groups/DpbGroup/</url>
</mirror>

更新eclipse的配置

android搭建maven私服 如何搭建maven服务器_android搭建maven私服_23

注意:一定把勾去掉,不然不会远程下载。

android搭建maven私服 如何搭建maven服务器_jar包_24

maven项目中通过坐标下载测试。

android搭建maven私服 如何搭建maven服务器_jar包_25

<dependency>
  <groupId>c3p0</groupId>
  <artifactId>c3p0</artifactId>
  <version>0.9.1.2</version>
</dependency>

android搭建maven私服 如何搭建maven服务器_上传_26

android搭建maven私服 如何搭建maven服务器_上传_27

##上传jar包私服
1.在conf/setting.xml文件中配置认证

<server>
		<id>releases</id>
		<username>admin</username>
		<password>admin123</password>
	</server>
	<server>
		<id>snapshots</id>
		<username>admin</username>
		<password>admin123</password>
	</server>

2.在将要上传的pom.xml中配置jar上传的路径

<!-- 配置上传私服路径 -->
  <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>

3.执行上传命令 deploy

android搭建maven私服 如何搭建maven服务器_jar包_28

android搭建maven私服 如何搭建maven服务器_jar包_29

android搭建maven私服 如何搭建maven服务器_上传_30

###查看上传结果

android搭建maven私服 如何搭建maven服务器_android搭建maven私服_31

###上传特定jar包到私服

Oracle驱动包

android搭建maven私服 如何搭建maven服务器_android搭建maven私服_32

android搭建maven私服 如何搭建maven服务器_android搭建maven私服_33

android搭建maven私服 如何搭建maven服务器_上传_34

android搭建maven私服 如何搭建maven服务器_android搭建maven私服_35

android搭建maven私服 如何搭建maven服务器_上传_36

android搭建maven私服 如何搭建maven服务器_maven_37

##从私服上下载jar包
在conf/setting.xml中配置 模板

<profile>
		<id>dev</id>
		<repositories>
			<repository>
				<id>nexus</id>
				<url>http://localhost:8081/nexus/content/groups/public/</url>
				<!--是否下载releases构件 -->
				<releases>
					<enabled>true</enabled>
				</releases>
				<!--是否下载snapshots构件 -->
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
			</repository>
		</repositories>
		
		<pluginRepositories>
			<pluginRepository>
				<id>public</id>
				<name>Public_Repositories</name>
				<url>http://localhost:8081/nexus/content/groups/public/</url>
			</pluginRepository>
		</pluginRepositories>
	</profile>

###激活模板

android搭建maven私服 如何搭建maven服务器_jar包_38

###测试使用
使用Oracle的jar包

android搭建maven私服 如何搭建maven服务器_android搭建maven私服_39