什么是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

最新文章

  1. memcached安装配置+基础操作
  2. linux 命令总结
  3. Oracle 数据库对象
  4. Squid configuration directives 3.0
  5. 【LVM】LVM自动扩容脚本
  6. [Qt] 界面美化 [2013-06-17更新](转载)
  7. Centos7下安装iF.svnadmin实现web方式管理svn(源码安装)
  8. NOI2012 Day2
  9. 3-14 JS基础知识01
  10. python 中如何导入一个自己创建的模块
  11. 蓝桥杯比赛javaB组练习《生日蜡烛》
  12. NIO高性能框架-Netty
  13. Linux网路查看工具
  14. MySQL主从数据库的安装
  15. [转]magento性能优化的教程(非常详细)
  16. linux运维之分析日志相关命令(1)
  17. bat如何批量删除指定部分文件夹名的文件夹
  18. 《A_Pancers》第一次作业:团队亮相
  19. 使用存储过程非常慢,但是直接执行SQL很快
  20. 静态HTML服务器

热门文章

  1. Django---进阶2
  2. Oracle 对表的基本CURD操作
  3. 利用docker部署elk交换机日志分析
  4. 数据可视化之powerBI技巧(二)Power BI性能分析器,原来还有这个功能
  5. 临时解决GitHub的raw.githubusercontent.com无法连接问题
  6. CAS底层原理与ABA问题
  7. vue学习(十一) v-for使用的注意事项:2.2.0+之后的版本里,当在组件中使用v-for时,key是必须的,它是用来表示唯一身份的
  8. VS Code 上那些沙雕插件
  9. integrator.setTimeout 设置一个超时时间,超过这个时间之后,扫描的 Activity 将会被 finish 。
  10. ELK5.6.4+Redis+Filebeat+Nginx(CentOS7.4)