当前位置: 首页 > article >正文

Nexus简介及小白使用IDEA打包上传到Nexus3私服详细教程_ider2021 引用 nexus 上传

使用IDEA打包上传到Nexus3私服
    • 一、Nexus是什么
      • 二、使用Nexus3搭建maven私服
      • 三、IDEA打包上传到Nexus3私服
        • 1.配置 .m2 下的 settings.xml
          • 1.配置 IDEA 项目 下的 pom.xml
          • 3.配置上传地址,地址去私服中copy
          • 4.其他配置(可忽略)
          • 5.settings.xml完整配置(来源网络,仅供参考)
          • 6.IDEA打包上传

一、Nexus是什么

开始在使用Maven时,总是会听到nexus这个词,一会儿maven,一会儿nexus,为什么它总是和maven一起被提到呢?

Maven作为一个优秀的构建工具依赖管理工具项目信息管理工具,在进行依赖管理的时候,通过pom.xml里面的

<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>2.1.0</version>
</dependency>

来精准定位找到对应的Java类库。在这个过程当中我们需要从仓库去找到对应的jar包引入到我们的项目当中,由此我们解决了合作开发中依赖增多、版本不一致、版本冲突、依赖臃肿等问题。
在这里插入图片描述
Maven有本地仓库远程仓库两种,当Maven根据坐标寻找构件时,它首先会查看本地仓库,如果本地仓库存在此构件,则直接使用;如果本地仓库不存在此构件,或者需要查看是否有更新的构件版本,Maven会去远程仓库查找,发现需要的构件之后,下载到本地仓库再使用。

在这里插入图片描述
说到此,相信大家也明白了,Nexus是一种远程仓库也是私服的一种

SNAPSHOT
快照版本,在 maven 中 SNAPSHOT 版本代表正式发布(release)的版本之前的开发版本,在 pom 中用 x.y-SNAPSHOT 表示。

RELEASE
发布版本,稳定版本,在 maven 中 RELEASE 代表着稳定的版本,unchange,不可改变的,在 maven 中 SNAPSHOT 与 RELEASE 版本在策略上是完全不同的方式,SNAPSHOT 会根据你的配置不同,频繁的从远程仓库更新到本地仓库;而 RELEASE 则只会在第一次下载到本地仓库,以后则会先直接从本地仓库中寻找。

二、使用Nexus3搭建maven私服

在网上找到几个参考:
Windows中使用Nexus3搭建maven私服
maven 私服 nexus3.x 搭建 与使用
Maven私服Nexus3.x环境构建操作记录

三、IDEA打包上传到Nexus3私服

1.配置 .m2 下的 settings.xml

首先,这个文件在系统盘当前设备登录用户的.m2文件下,加入认证机制
在这里插入图片描述
没有就去网上copy一个配置好的,自己配置容易出错

->settings.xml<-

<servers>
	<server>
	      <id>nexus</id>
	      <username>admin</username>
	      <password>admin123</password>
     </server>
     <server>
	      <id>maven-snapshots</id>
	      <username>admin</username>
	      <password>admin123</password>
     </server>
      <server>
	      <id>maven-releases</id>
	      <username>admin</username>
	      <password>admin123</password>
     </server>
     <server>
		<id>rdc-releases</id>
		<username>xxxxxxxxx</username>
		<password>xxxxx</password>
	</server>
	<server>
		<id>rdc-snapshots</id>
		<username>xxxxxxxxx</username>
		<password>xxxx</password>
	</server>
</servers>



1.配置 IDEA 项目 下的 pom.xml
 <distributionManagement>
    <repository>
      <id>nexus</id>
      <name>nexus</name>
      <url>http://xxxx:port/repository/maven-snapshots/</url>
    </repository>

    <snapshotRepository>
      <id>maven-snapshots</id>
      <name>maven-snapshots</name>
      <url>http://xxxx:port/repository/maven-snapshots/</url>
    </snapshotRepository>
  </distributionManagement>

这里标签中的id对应第一条server中的id ,url取得值可以直接在这里写,也可以如下图中settings文件中的值,name可以自定义
->settings.xml<-

<profile>
	<altReleaseDeploymentRepository> http://xxxx:port/repository/maven-snapshots/ </altReleaseDeploymentRepository>
	<altSnapshotDeploymentRepository> http://xxxx:port/repository/maven-snapshots/</altSnapshotDeploymentRepository>
</profile>

同样,上面pom.xml改成如下格式

<distributionManagement>
    <repository>
      <id>nexus</id>
      <name>nexus</name>
      <url>${altReleaseDeploymentRepository}</url>
    </repository>

    <snapshotRepository>
      <id>maven-snapshots</id>
      <name>maven-snapshots</name>
      <url>${altSnapshotDeploymentRepository}</url>
    </snapshotRepository>
  </distributionManagement>

3.配置上传地址,地址去私服中copy
<profile> 
	<!--profile 的 id-->
	<id>dev</id> 
	<repositories> 
		<repository> 
			<!--仓库 id,repositories 可以配置多个仓库,保证 id 不重复-->
			<id>nexus</id> 
			<!--仓库地址,即 nexus 仓库组的地址-->
			<url>http://localhost:8081/nexus/content/groups/public/</url> 
			<!--是否下载 releases 构件-->
			<releases> 
				<enabled>true</enabled> 
			</releases> 
			<!--是否下载 snapshots 构件-->
			<snapshots> 
				<enabled>true</enabled> 
			</snapshots> 
		</repository> 
	</repositories> 
	<pluginRepositories> 
		<!-- 插件仓库,maven 的运行依赖插件,也需要从私服下载插件 -->
		<pluginRepository> 
			<!-- 插件仓库的 id 不允许重复,如果重复后边配置会覆盖前边 -->
			<id>central</id> 
			<name>Nexus Plugin Repository</name> 
			<url>http://central</url> 
			<releases>
               <enabled>true</enabled>
            </releases>
            <snapshots>
               <enabled>true</enabled>
            </snapshots>
		</pluginRepository> 
	</pluginRepositories> 
</profile>


4.其他配置(可忽略)

比如配置阿里的镜像,映射阿里中央仓库(下载jar包快一点)

<mirrors>
   <mirror>
    <id>alimaven</id>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    <mirrorOf>central</mirrorOf>       
  </mirror>
</mirrors>


配置本地仓库(无需联网使用jar包)

<localRepository>E:\maven_repository</localRepository>

5.settings.xml完整配置(来源网络,仅供参考)
<?xml version="1.0" encoding="UTF-8"?>
 
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
 
    <!-- 本地仓库地址 -->
    <localRepository>D:\mvn_repo\repository</localRepository>
 
 
    <!-- 以下配置为上传jar包配置 -->
    <pluginGroups>
 
    </pluginGroups>
 
    <proxies>
 
    </proxies>
 
    <servers>
        <server>
            <!-- id,对应项目里面pom.xml里面distributionManagement配置的id -->
            <id>maven-releases</id>
            <!-- 登录nexus的用户名 -->
            <username>admin</username>
            <!-- 登录nexus的密码 -->
            <password>admin123</password>
        </server>
        <server>
            <!-- id,对应项目里面pom.xml里面distributionManagement配置的id -->
            <id>maven-snapshots</id>
            <!-- 登录nexus的用户名 -->
            <username>admin</username>
            <!-- 登录nexus的密码 -->
            <password>admin123</password>
        </server>
        <!-- 配置拦截器mirror登录的用户名密码。他会拦截所有的请求到mirror指定的地址下载jar包 如果只需要去私服下载jar包则只需配置此项 -->
        <server>
            <!-- id,对应mirror中id -->
            <id>nexus</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
    </servers>
 
 
    <!-- 以下配置为下载jar包配置 通用 -->
 
    <mirrors>
        <!-- 强制让jar包下载走私服 -->
        <mirror>
            <id>nexus</id>
            <mirrorOf>*</mirrorOf>
            <url>http://192.168.65.129:8081/repository/maven-public/</url>
        </mirror>
    </mirrors>
 
    <profiles>
        <profile>
            <!-- 对应activeProfiles-activeProfile的内容 -->
            <id>nexus</id>
            <!-- 仓库地址 -->
            <repositories>
                <repository>

http://www.kler.cn/a/535000.html

相关文章:

  • B站自研的第二代视频连麦系统(上)
  • 初阶数据结构:树---堆
  • Oh3.2项目升级到Oh5.0(鸿蒙Next)具体踩坑记录(一)
  • 6 加密技术与认证技术
  • 蓝桥杯备赛题目练习(一)
  • 两种文件类型(pdf/图片)打印A4半张纸方法
  • 怎么定义 vue-router 的动态路由?
  • 资源查找网址
  • es match 可查 而 term 查不到 问题分析
  • 前端开发知识梳理 - HTMLCSS
  • 202617读书笔记|《清溪俳句三百》——春有樱花,夏有蝉,秋有红叶,冬有雪
  • 寒假2.5
  • 【数据结构】(6) LinkedList 链表
  • 科技赋能数字内容体验的核心技术探索
  • 足球俱乐部管理系统的设计与实现
  • 【落羽的落羽 数据结构篇】单链表
  • Leetcode—340. 至多包含 K 个不同字符的最长子串【中等】Plus(力扣159变体罢了改个参数而已)
  • shell检测文件是windows格式还是unix
  • 智能门铃市场:开启智能家居新时代
  • linux中,软硬链接的作用和使用
  • 大数据方向知识图谱及发展前景分析
  • mysql 学习9 约束-作用于表中字段上的规则,目的是保证数据的正确,有效性和完整性,约束关键字,外键约束
  • MySQL万能备份脚本
  • 股指入门:股指期货是什么意思?在哪里可以做股指期货交易?
  • 阿里云 | DeepSeek人工智能大模型安装部署
  • 如何利用Python爬虫获取商品销量详情实战指南