使用nexus搭建maven私库
什么是nexus?
nexus是一个maven仓库管理器,使用nexus可以快速便捷的搭建自己的maven私有仓库。
docker安装nexus
拉取镜像
docker pull sonatype/nexus3
后台执行镜像
docker run -d -p 8081:8081 --name nexus-dev
查看nexus容器是否启动
访问本地的nexus
在浏览器url地址中输入localhost:8081,如果此时未能成功加载,等待几秒后再尝试刷新浏览器。
成功访问后,点击右上角sigin,按照提示从指定目录下获取admin账号的密码。
添加常用代理源
选择maven2代理方式
添加阿里云代理源
设置常用代理到maven-public
maven-public是一个聚合仓库,当从这个仓库中获取依赖时,它会从成员列表中依次往下遍历,从对应的成员仓库中获取依赖。
设置release仓库可重复发布
配置release仓库可重复发布之后,可以重复发布同一个版本号的依赖。这里大家可以根据实际情况勾选是否启用。
本地maven配置
配置好私有仓库之后,我们需要修改本地的maven配置和项目中的pom文件才能够跟私有仓库进行互动操作。
修改settings.xml
这里需要注意settings.xml文件的优先级(用户级别>全局设置>自定义路径),具体的配置看下面的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:\Program Files\Maven\repository</localRepository>
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>chenhao.123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/repository/maven-public/</url>
</mirror>
<profiles>
<profile>
<id>jdk-1.8</id>
<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>
</profile>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>maven-public</id>
<url>http://localhost:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>maven-snapshots</id>
<url>http://localhost:8081/repository/maven-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>maven-releases</id>
<url>http://localhost:8081/repository/maven-releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven-public</id>
<url>http://localhost:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>maven-snapshots</id>
<url>http://localhost:8081/repository/maven-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>maven-releases</id>
<url>http://localhost:8081/repository/maven-releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>jdk-1.8</activeProfile>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
创建一个maven项目A作为依赖提供者
这里在idea创建一个maven模板的项目即可,没有什么特别的操作。
修改A项目的pom.xml
<distributionManagement>
<repository>
<id>nexus</id>
<name>releases Repository</name>
<url>http://127.0.0.1:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus</id>
<name>snapshots Repository</name>
<url>http://127.0.0.1:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
在A项目中创建一个Math作为测试
package com.chenhao.util;
public class Math {
public static int add(int a, int b){
return a+b;
}
}
将项目A的jar包发布到私有仓库
在idea项目右边的maven工具来中,点击deploy按钮,查看控制台输出
查看nexus上是否存在这个依赖
创建一个maven项目B作为依赖使用者
这里创建一个项目B来作为依赖的使用者,并且需要注意的是,在项目A中使用了deploy操作,此时已经将依赖上传到本地仓库。所以此时应该将本地仓库中的依赖删除。
package com.chenhao;
import com.chenhao.util.Math;
public class Main {
public static void main(String[] args) {
System.out.println(Math.add(1, 1));
}
}
修改项目B的pom.xml
<dependencies>
<dependency>
<groupId>com.chenhao</groupId>
<artifactId>example</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
运行项目B
使用nexus搭建maven私库的更多相关文章
- Docker搭建Nexus(Maven私库)
0.镜像的查找:docker search nexus 1.拉取官方镜像:docker pull sonatype/nexus3 2.创建了自己的目录 (/opt/nexus/nexus-data) ...
- maven私库nexus2.3.0-04迁移升级到nexus-3.16.1-02(异机迁移备份)
环境信息: nexus2.3.0-04安装在32位Windows server 2003系统上 安装位置信息如下: 仓库迁移 Nexus的构件仓库都保存在sonatype-work目录中,nexus2 ...
- nexus 搭建maven本地仓库
使用Nexus搭建Maven本地仓库 阅读目录 序 Nexus 序 在工作中可能存在有些开发机器不能上网,大量的机器获取jar包会导致公司网络很慢,还有时候公司会自己发布自己的项目版本,其他的项目 ...
- Maven使用笔记(五)Sonatype Nexus 搭建Maven 私服
1. 为什么使用Nexus 如果没有私服,我们所需的所有构件都需要通过maven的中央仓库和第三方的Maven仓库下载到本地, 而一个团队中的所有人都重复的从maven仓库下载构件无疑加大了仓库的负载 ...
- Maven学习二:使用Nexus搭建Maven私服及相关配置
处于安全等原因的考虑,一些企业内部网络是不允许访问外部网络的,但是项目内部搭建的项目又是Maven架构,这样就需要企业在内部网络中搭建自己的Maven仓库服务,再者一些大型企业或者内部模块化组件化划分 ...
- nexus搭建maven私服及私服jar包上传和下载
nexus搭建maven私服及私服jar包上传和下载 标签: nexus管理maven库snapshot 2017-06-28 13:02 844人阅读 评论(0) 收藏 举报 分类: Maven(1 ...
- ubuntu下使用Nexus搭建Maven私服
ubuntu下使用Nexus搭建Maven私服 1.私服简介: 私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件.有了私服之后,当 Maven 需要下载构件时,直接请求私服, ...
- Windows使用Nexus搭建Maven私服
简介 Maven私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件,有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库,否则,私服请求外部的 ...
- 在 Docker 搭建 Maven 私有库
在 Docker 搭建 Maven 私有库 小引 If you are developing software without a repository manager you are likely ...
随机推荐
- 一题搞定static关键字
基础不牢,地动山摇 开篇一道题,考察代码执行顺序: public class Parent { static { System.out.println("Parent static init ...
- JS基础知识点(一)
原始类型 null undefined boolean number string symbol 注意 原始类型存储的都是值,是没有函数可以调用的,但实际上除null和undefined外,其他类型使 ...
- 机器学习实战基础(十六):sklearn中的数据预处理和特征工程(九)特征选择 之 Filter过滤法(三) 总结
过滤法总结 到这里我们学习了常用的基于过滤法的特征选择,包括方差过滤,基于卡方,F检验和互信息的相关性过滤,讲解了各个过滤的原理和面临的问题,以及怎样调这些过滤类的超参数.通常来说,我会建议,先使用方 ...
- 爬虫04 /asyncio、selenium规避检测、动作链、无头浏览器
爬虫04 /asyncio.selenium规避检测.动作链.无头浏览器 目录 爬虫04 /asyncio.selenium规避检测.动作链.无头浏览器 1. 协程asyncio 2. aiohttp ...
- JavaScript动画基础:canvas绘制简单动画
动画是将静止的画面变为动态的艺术.实现由静止到动态,主要是靠人眼的视觉残留效应.视觉残留也叫视觉暂留现象,物体在快速运动时, 当人眼所看到的影像消失后,人眼仍能继续保留其影像0.1~0.4秒左右的图像 ...
- JavaScript 基础 学习(三)
JavaScript 基础 学习(三) 事件三要素 1.事件源: 绑定在谁身上的事件(和谁约定好) 2.事件类型: 绑定一个什么事件 3.事件处理函数: 当行为发生的时候,要执行哪一个函数 ...
- Netty源码阅读之如何将TCP的读写操作和指定线程绑定
原文链接:http://xueliang.org/article/detail/20200712234015993 前言 在Netty的线程模型中,对于一个TCP连接的读写操作,都是由一个单线程完成的 ...
- ffmpeg播放器实现详解 - 框架搭建
ffplay是ffmpeg源码中一个自带的开源播放器实例,同时支持本地视频文件的播放以及在线流媒体播放,功能非常强大. FFplay: FFplay is a very simple and port ...
- Atlassian Confluence 5.1.2 破解版部署
Atlassian Confluence(简称Confluence)是一个专业的wiki程序.它是一个知识管理的工具,通过它可以实现团队成员之间的协作和知识共享.Confluence 不是一个开源软件 ...
- 最小生成树的java实现
文章目录 一.概念 二.算法 2.1 Prim算法 2.2 Kruskal算法 笔记来源:中国大学MOOC王道考研 一.概念 连通图:图中任意两点都是连通的,那么图被称作连通图 生成树:连通图包含全部 ...