Maven私服(Java升级计划7)

私服简介

私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件。有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库;否则,私服请求外部的远程仓库,将构件下载到私服,再提供给本地仓库下载。
162358583957595.png162359096298261.png
我们可以使用专门的 Maven 仓库管理软件来搭建私服,比如:Apache ArchivaArtifactorySonatype Nexus。这里我们使用 Sonatype Nexus。

上面这部分转载自博客Nexus安装、使用说明、问题总结,由于使用转载博客的安装无法进行,这里我说明怎么安装

安装nexus

nexus下载地址:https://www.sonatype.com/download-oss-sonatype
image.png

解压

image.png
进入bin目录
image.png
打开cmd窗口,在这个目录下进行安装

启动服务 nexus.exe /run (启动成功后不要关闭命令行窗口)

image.png
当看到图中所示界面时,表示启动成功
image.png

安装服务 nexus.exe /install (重新使用新的命令行安装,可能出现权限不足,请以管理员身份运行命令行)

怎么打开管理员身份的cmd窗口

image.png

安装

image.png

启动服务 net start nexus

image.png

停止服务 net stop nexus

访问页面 http://localhost:8081/

image.png
如果不知道默认端口号是多少,可以进入目录 etc/下,有一个文件nexus-default.properties
当中就有默认端口号
image.png

初始登录

3.17版本密码改成随即的了,而且登录时候提示密码在/nexus-data/admin.password里
image.png
因为登录后,nexus会删除这个文件,这里我保留了windows的路径
image.png

Nexus的使用

从Nexus私服下载资源

找到maven配置文件settings.xml,添加如下配置

  • 1)添加镜像配置,将所有访问外网仓库的请求指向私服
 <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://localhost:8081/repository/maven-public/</url>
</mirror> 
  • 2)添加profiles,所有请求均通过镜像
<profile>
      <id>nexus</id>
      <repositories>
		  <repository>
		  <id>central</id>
		  <url>https://repo1.maven.org/maven2</url>
		  <releases><enabled>true</enabled></releases>
		  <snapshots><enabled>true</enabled></snapshots>
		  </repository>
      </repositories>
      <pluginRepositories>
		  <pluginRepository>
		  <id>central</id>
		  <url>https://repo1.maven.org/maven2</url>
		  <releases><enabled>true</enabled></releases>
		  <snapshots><enabled>true</enabled></snapshots>
		  </pluginRepository>
      </pluginRepositories>
</profile>
  • 3)生效配置
<activeProfiles>
    <activeProfile>nexus</activeProfile>
</activeProfiles>

# Java  maven 

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×