Nexus3之在Window中搭建Maven私服

Nexus3之在Window中搭建Maven私服

文章目录

  • Nexus3之在Window中搭建Maven私服
  • [1. 下载](#1. 下载)
  • [2. 安装](#2. 安装)
  • [3. 创建用户及仓库](#3. 创建用户及仓库)
  • [4. maven的setting.xml文件修改](#4. maven的setting.xml文件修改)
  • [5. POM.xml文件修改](#5. POM.xml文件修改)

1. 下载

官网: https://www.sonatype.com/download-oss-sonatype

下载OSS免费版,如下载版本为:Nexus-3.16.0-latest-win64.zip

2. 安装

  • 先将Nexus-3.16.0-latest-win64.zip文件解压到指定目录,如:D:\Nexus-3.16.0目录下
  • 将D:\Nexus-3.16.0\nexus-3.16.2-01\bin 添加到环境变量的path路径后面
  • 以管理员身份打开cmd窗口,输入下面命令安装
shell 复制代码
# 注册服务
nexus /install Nexus3 #此命令直接注册到服务中,名称为Nexus3
# 启动服务
net start Nexus3

3. 创建用户及仓库

浏览器中打开Nexus图形界面后,输入管理员密码登录,默认账户/密码为 admin/admin123

注意:最新版本的admin会在安装目录下的admin.password文件中,首次登陆后修改admin密码接口,如:3.39.0-01的admin密码位置如下

Your admin user password is located in E:\warehouse\nexus-3.39.0-01\sonatype-work\nexus3\admin.password on the server.

  1. 创建一个用户,比如 yuan/yuan123
  2. 配置一个代理(proxy)仓库,如使用阿里云的maven仓库,URL: http://maven.aliyun.com/nexus/content/groups/public/
  3. 创建两个hosted(宿主)类型的仓库
shell 复制代码
#名称为yuan-releases的hosted仓库
http://localhost:8081/repository/yuan-releases/
#名称yuan-sanpshots的hosted仓库
http://localhost:8081/repository/yuan-snapshots/
  1. 创建一个group类型的仓库
shell 复制代码
#名称为yuan-public的group类型仓库
http://localhost:8081/repository/yuan-public/
  1. 将yuan-releases 与 yuan-snapshots 添加到仓库组 yuan-public中

4. maven的setting.xml文件修改

  1. server配置
xml 复制代码
<servers> 
	<!--发布版-->
	<server>
		 <id>yuan-releases</id>
		 <username>yuan</username>
		 <password>yuan123</password>
	 </server>
	<!--快照版-->
	 <server>
		 <id>yuan-snapshots</id>
		 <username>yuan</username>
		 <password>yuan123</password>
	 </server>
  </servers>
  1. mirrors配置
xml 复制代码
 <mirrors>  
	 <!--使用阿里云的镜像仓库-->
	 <mirror>
		<id>nexus-aliyun</id>
		<name>Nexus aliyun</name>
		<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
		<mirrorOf>central</mirrorOf>
	 </mirror>	
	 <!--私服地址-->
	<mirror>
            <id>nexus-yuan</id>
            <mirrorOf>*</mirrorOf>
            <name>Nexus yuan</name>
            <url>http://localhost:8081/repository/yuan-public/</url>
    </mirror>
  </mirrors>
  1. profiles编写
xml 复制代码
<profiles>
    <!--使用指定的jdk版本-->
	<profile>
      <id>jdk8</id>
      <activation>
		<activeByDefault>true</activeByDefault>
        <jdk>1.8</jdk>
      </activation>
      <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>
		<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
      </properties>
      <!--私服库配置-->
	  <repositories>
        <repository>
            <id>nexus-yuan</id>
            <name>nexus yuan group</name>
            <url>http://localhost:8081/repository/yuan-public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <!--私服插件配置-->
    <pluginRepositories>
        <pluginRepository>
            <id>nexus-yuan</id>
            <name>nexus yuan group</name>
            <url>http://localhost:8081/repository/yuan-public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
    </profile>
  </profiles>
  <!--激活名称为jdk8的porfile-->
  <activeProfiles>
    <activeProfile>jdk8</activeProfile>
  </activeProfiles>

5. POM.xml文件修改

一般将私服配置到父工程的pom.xml文件中

  1. 在pom.文件中添加下面内容
xml 复制代码
<distributionManagement>
        <!--发布版仓库-->
        <repository>
            <!--这里的id配置一定要与settin.xml文件中server配置中的id一致,否则可能出现405错误-->
            <id>yuan-releases</id>
            <name>nexus yuan group</name>
            <url>http://localhost:8081/repository/yuan-releases/</url>
        </repository>
        <!--快照版仓库-->
        <snapshotRepository>
            <!--这里的id配置一定要与settin.xml文件中server配置中的id一致-->
            <id>yuan-snapshots</id>
            <name>nexus yuan group</name>
            <url>http://localhost:8081/repository/yuan-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
  1. 完成后,可在idea中执行maven的install命令进行安装
  2. install命令成功后,可执行deploy命令将jar发布的maven私服库中。
相关推荐
ChinaRainbowSea3 分钟前
补充:问题:CORS ,前后端访问跨域问题
java·spring boot·后端·spring
KiddoStone13 分钟前
多实例schedule job同步数据流的数据一致性设计和实现方案
java
岁忧34 分钟前
(LeetCode 每日一题) 1865. 找出和为指定值的下标对 (哈希表)
java·c++·算法·leetcode·go·散列表
YuTaoShao37 分钟前
【LeetCode 热题 100】240. 搜索二维矩阵 II——排除法
java·算法·leetcode
考虑考虑1 小时前
JDK9中的dropWhile
java·后端·java ee
想躺平的咸鱼干2 小时前
Volatile解决指令重排和单例模式
java·开发语言·单例模式·线程·并发编程
hqxstudying2 小时前
java依赖注入方法
java·spring·log4j·ioc·依赖
·云扬·2 小时前
【Java源码阅读系列37】深度解读Java BufferedReader 源码
java·开发语言
Bug退退退1233 小时前
RabbitMQ 高级特性之重试机制
java·分布式·spring·rabbitmq
小皮侠3 小时前
nginx的使用
java·运维·服务器·前端·git·nginx·github