什么是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私库的更多相关文章

  1. Docker搭建Nexus(Maven私库)

    0.镜像的查找:docker search nexus 1.拉取官方镜像:docker pull sonatype/nexus3 2.创建了自己的目录 (/opt/nexus/nexus-data) ...

  2. maven私库nexus2.3.0-04迁移升级到nexus-3.16.1-02(异机迁移备份)

    环境信息: nexus2.3.0-04安装在32位Windows server 2003系统上 安装位置信息如下: 仓库迁移 Nexus的构件仓库都保存在sonatype-work目录中,nexus2 ...

  3. nexus 搭建maven本地仓库

    使用Nexus搭建Maven本地仓库   阅读目录 序 Nexus 序 在工作中可能存在有些开发机器不能上网,大量的机器获取jar包会导致公司网络很慢,还有时候公司会自己发布自己的项目版本,其他的项目 ...

  4. Maven使用笔记(五)Sonatype Nexus 搭建Maven 私服

    1. 为什么使用Nexus 如果没有私服,我们所需的所有构件都需要通过maven的中央仓库和第三方的Maven仓库下载到本地, 而一个团队中的所有人都重复的从maven仓库下载构件无疑加大了仓库的负载 ...

  5. Maven学习二:使用Nexus搭建Maven私服及相关配置

    处于安全等原因的考虑,一些企业内部网络是不允许访问外部网络的,但是项目内部搭建的项目又是Maven架构,这样就需要企业在内部网络中搭建自己的Maven仓库服务,再者一些大型企业或者内部模块化组件化划分 ...

  6. nexus搭建maven私服及私服jar包上传和下载

    nexus搭建maven私服及私服jar包上传和下载 标签: nexus管理maven库snapshot 2017-06-28 13:02 844人阅读 评论(0) 收藏 举报 分类: Maven(1 ...

  7. ubuntu下使用Nexus搭建Maven私服

    ubuntu下使用Nexus搭建Maven私服 1.私服简介: 私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件.有了私服之后,当 Maven 需要下载构件时,直接请求私服, ...

  8. Windows使用Nexus搭建Maven私服

    简介 Maven私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件,有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库,否则,私服请求外部的 ...

  9. 在 Docker 搭建 Maven 私有库

    在 Docker 搭建 Maven 私有库 小引 If you are developing software without a repository manager you are likely ...

随机推荐

  1. stb_image multiple definition of first defined here 多文件包含问题

    首先吐槽一下,网上的其他的一些内容都是瞎写,根本没有指出问题的根本原因,使用时出现异常情况不能自己解决也说明了C语言基础不牢固, 该头文件可以分为两种情况使用(推荐使用办法2,办法1中有解释原因)(任 ...

  2. Uni-app页面路由区分注意事项

    总结Tips: (1)navigateTo,redirectTo 只能打开非 tabBar页面 (2)switchTab只能打开 TabBar 页面 (3)reLaunch可以打开任意界面 (4)页面 ...

  3. redis 集群方案及搭建

    由于Redis出众的性能,其在众多的移动互联网企业中得到广泛的应用.Redis在3.0版本前只支持单实例模式,虽然现在的服务器内存可以到100GB.200GB的规模,但是单实例模式限制了Redis没法 ...

  4. 从零开始实现multipart/form-data数据提交

    在HTTP服务应用中进行数据提交一般都使用application/json,application/x-www-form-urlencoded和multipart/form-data这几种内容格式.这 ...

  5. java8的parallelStream提升数倍查询效率

    业务场景 在很多项目中,都有类似数据汇总的业务场景,查询今日注册会员数,在线会员数,订单总金额,支出总金额等...这些业务通常都不是存在同一张表中,我们需要依次查询出来然后封装成所需要的对象返回给前端 ...

  6. python 并发专题(六):协程相关函数以及实现(gevent)

    文档资源 http://sdiehl.github.io/gevent-tutorial/ 一.协程实现 线程和协程 既然我们上面也说了,协程也被称为微线程,下面对比一下协程和线程: 线程之间需要上下 ...

  7. Integer和Long部分源码分析

    Integer和Long的java中使用特别广泛,本人主要一下Integer.toString(int i)和Long.toString(long i)方法,其他方法都比较容易理解. Integer. ...

  8. A Great Alchemist 最详细的解题报告

    题目来源:A Great Alchemist A Great Alchemist Time limit : 2sec / Stack limit : 256MB / Memory limit : 25 ...

  9. Docker 基础知识 - 使用绑定挂载(bind mounts)管理应用程序数据

    绑定挂载(bind mounts)在 Docker 的早期就已经出现了.与卷相比,绑定挂载的功能有限.当您使用绑定挂载时,主机上的文件或目录将挂载到容器中.文件或目录由其在主机上的完整或相对路径引用. ...

  10. 自学 Python 到什么程度能找到工作,1300+ 条招聘信息告诉你答案

    随着移动互联网的发展以及机器学习等热门领域带给人们的冲击,让越来越多的人接触并开始学习 Python.无论你是是科班出身还是非科班转行,Python 无疑都是非常适合你入门计算机世界的第一门语言,其语 ...