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私服库中。
相关推荐
Resean02232 小时前
讲透Java(14)泛型的本质:类型擦除与桥接方法
java·开发语言
智能收银研究所2 小时前
收银系统选型对比:美团、客如云、拉卡拉、收钱吧各适合什么门店
java·前端·数据库
七夜zippoe4 小时前
金仓 Kingbase 安装与 Java 连接(保姆级):从装库到 JDBC 跑通全记录
java·数据库·jdbc·kingbase·金仓
nice_lcj5205 小时前
Bean 的作用域:单例、原型及特殊作用域
java·spring·面试·原型·单例·bean作用域
这个昵称不容易7 小时前
SpringBoot 基于web的酒店客房管理系统设计与实现:176 个 Java 文件 233 个接口,会员预约到退房一条链
java·springboot·毕设
nice_lcj5207 小时前
Spring AOP 面向切面编程:切面解决什么问题
java·spring·面试·aop·切面·面向切面编程
考虑考虑8 小时前
JDK27的LazyConstant
java·后端·java ee
知识搬运临时工8 小时前
加一层连接池,TPS 从 26438 掉到 12923
java·后端
琳少_8 小时前
java课堂笔记
java·开发语言·数据库·笔记
Helix25010 小时前
JDK安全编码实战:SQL注入、XSS、反序列化等10类漏洞防护完整指南|2026
java·安全·xss·sql注入·反序列化·安全编码·owasp