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私服库中。
相关推荐
非 白2 分钟前
【Java分布式】Nacos注册中心
java·开发语言·nacos·注册中心
吃海鲜的骆驼7 分钟前
服务异步通讯与RabbitMQ
java·分布式·后端·rabbitmq
羱滒11 分钟前
sql调优之数据库开发规范
java·数据库·数据库开发
Forget the Dream39 分钟前
设计模式之责任链模式
java·c++·设计模式·责任链模式
jonyleek42 分钟前
「JVS更新日志」低代码、企业会议、智能BI、智能排产2.26更新说明
java·大数据·低代码·数据分析·软件需求
计算机小白一个1 小时前
蓝桥杯 Java B 组之最短路径算法(Dijkstra、Floyd-Warshall)
java·数据结构·算法·蓝桥杯
曼岛_1 小时前
[密码学实战]Java实现SM4加解密(ecb,cbc)及工具验证
java·密码学
Forget the Dream2 小时前
设计模式之代理模式
java·c++·设计模式·代理模式
帅的飞起来2 小时前
设计模式--spring中用到的设计模式
java·spring·设计模式
張葒兵3 小时前
记一次命令行启动springboot项目的问题 java -jar的问题
java·spring boot·jar