在局域网内搭建maven私有仓库,可避免每次都从中央仓库下载公共jar包,另外将A模块作为二方库发布到私有仓库后,B模块可以很方便的引用,今天我们就来实战maven私有仓库的搭建和使用;

原文地址:http://blog.csdn.net/boling_cavalry/article/details/79059021

环境信息

  1. 安装私有仓库的机器是ubuntu16,IP是192.168.119.155;
  2. maven私有仓库的软件是nexus-2.14.5,请在官网下载;
  3. 在window10环境上做验证的使用,用到的maven版本是3.3.3,jdk版本1.8.0_111;

安装和启动nexus

  1. 打开/etc/profile,新增一行export RUN_AS_USER=root;
  2. 执行命令source /etc/profile,使刚才的配置生效;
  3. 从官网下载的是nexus-2.14.5-02-bundle.tar.gz,执行tar -zxvf nexus-2.14.5-02-bundle.tar.gz解压后,里面有两个目录:nexus-2.14.5-02和sonatype-work;
  4. 进入nexus-2.14.5-02/bin,执行./nexus start启动nexus;
  5. 进入nexus-2.14.5-02/logs,执行tail -f wrapper.log观察日志滚动信息,看到如下信息时nexus启动成功:
jvm 1    | 2018-01-13 21:38:44,671-0800 INFO  [jetty-main-1]  org.sonatype.nexus.webresources.internal.WebResourceServlet - Max-age: 30 days (2592000 seconds)
jvm 1 | 2018-01-13 21:38:44,698-0800 INFO [jetty-main-1] org.sonatype.nexus.bootstrap.jetty.InstrumentedSelectChannelConnector - Metrics enabled
jvm 1 | 2018-01-13 21:38:44,713-0800 INFO [jetty-main-1] org.eclipse.jetty.server.AbstractConnector - Started InstrumentedSelectChannelConnector@0.0.0.0:8081
jvm 1 | 2018-01-13 21:38:44,713-0800 INFO [jetty-main-1] org.sonatype.nexus.bootstrap.jetty.JettyServer - Running
jvm 1 | 2018-01-13 21:38:44,713-0800 INFO [WrapperListener_start_runner] org.sonatype.nexus.bootstrap.jetty.JettyServer - Started
jvm 1 | 2018-01-13 21:39:26,926-0800 INFO [qtp984089572-47] org.apache.shiro.nexus5727.FixedDefaultWebSessionManager - Global session timeout: 1800000 ms
jvm 1 | 2018-01-13 21:39:26,931-0800 INFO [qtp984089572-47] org.apache.shiro.session.mgt.AbstractValidatingSessionManager - Enabling session validation scheduler...
jvm 1 | 2018-01-13 21:39:26,944-0800 INFO [qtp984089572-47] org.apache.shiro.cache.ehcache.EhCacheManager - Using existing EHCache named [shiro-activeSessionCache]
jvm 1 | 2018-01-13 21:39:26,945-0800 INFO [qtp984089572-45] org.apache.shiro.nexus5727.FixedDefaultWebSessionManager - Global session timeout: 1800000 ms

登录

  1. 在浏览器输入地址:http://192.168.119.155:8081/nexus/
  2. 进入nexus首页后,点击右上角的”Log In”按钮,输入用户名”admin”,默认密码”admin123”;
  3. 点击左侧的”Repositories”按钮,看到已有的仓库,如下图: 

目前nexus已经开始正常工作了,接下来我们开始使用私有仓库;

使用私有仓库,配置

  1. 我的windows10开发环境要使用私有仓库,需要配置maven的信息,打开maven安装目录下的conf/settings.xml文件;
  2. 在mirrors节点下新增一个mirror节点,内容如下:
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.119.155:8081/nexus/content/groups/public/</url>
</mirror>

192.168.119.155是nexus机器的IP; 
3. 在profiles节点下新增一个profile节点,内容如下:

<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>

以上新增了中央仓库的相关信息; 
4. 新增一个activeProfiles节点,该节点和profiles节点一个层次,内容如下:

<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>

新建一个springboot工程

  • 新建一个基于maven构建的springboot的web工程,里面只有一个最简单的controller,在pom.xml所在目录下执行以下命令:
mvn clean package -Dmaven.test.skip=true
  • 可以看到如下信息,当前的maven已经在通过私有仓库下载:
[INFO] Building jar: D:\temp\201801\06\helloworld\target\helloworld-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:1.5.9.RELEASE:repackage (default) @ helloworld ---
Downloading: http://192.168.119.155:8081/nexus/content/groups/public/org/springframework/boot/spring-boot-loader-tools/1.5.9.RELEASE/spring-boot-loader-tools-1.5.9.RELEASE.pom
Downloaded: http://192.168.119.155:8081/nexus/content/groups/public/org/springframework/boot/spring-boot-loader-tools/1.5.9.RELEASE/spring-boot-loader-tools-1.5.9.RELEASE.pom (0 B at 0.0 KB/sec)
Downloading: http://192.168.119.155:8081/nexus/content/groups/public/org/springframework/boot/spring-boot-loader-tools/1.5.9.RELEASE/spring-boot-loader-tools-1.5.9.RELEASE.jar
Downloaded: http://192.168.119.155:8081/nexus/content/groups/public/org/springframework/boot/spring-boot-loader-tools/1.5.9.RELEASE/spring-boot-loader-tools-1.5.9.RELEASE.jar (0 B at 0.0 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:21 min
[INFO] Finished at: 2018-01-14T17:57:45+08:00
[INFO] Final Memory: 29M/164M
[INFO] ------------------------------------------------------------------------

已缓存信息

此时再从浏览器查看“Central”仓库的信息,发现里面已经缓存了前面的springboot工程所依赖的jar包,今后其他机器再需要这些jar包时,就可以直接从私有仓库上下载了,而私有仓库没有的jar包,也会由私有仓库下载并保存,然后提供给使用私有仓库的机器;

至此,nexus的安装和缓存jar包功能的使用实战已经完成,接下来的章节,我们会将本机的工程打包并发布到私有仓库;

实战maven私有仓库三部曲之一:搭建和使用的更多相关文章

  1. 实战maven私有仓库三部曲之三:Docker下搭建maven私有仓库

    本章是<实战maven私有仓库>系列的第三篇,在前两章中,我们先在linux搭建maven私有仓库,然后在开发环境使用此仓库,本章我们在docker下快速搭建maven私有仓库,然后像前面 ...

  2. 实战maven私有仓库三部曲之二:上传到私有仓库

    在上一章<实战maven私有仓库三部曲之一:搭建和使用>我们搭建了maven私有仓库,并体验了私有仓库缓存jar包的能力,避免了局域网内开发人员去远程中央仓库下载的痛苦等待,本章我们再来体 ...

  3. 用nexus搭建自己的maven私有仓库

    用nexus搭建自己的maven私有仓库  刚安装nexus时,nexus启动失败,启动不到1分钟,自动停止.后来查找到了原因: Java 6 Support EOLOracle's support ...

  4. 安装Maven并搭建Maven私有仓库

    一.说明 Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具.我们在进行Java代码开发的时候,Eclipse+Maven+Jetty是一个十 ...

  5. 使用nexus3.10搭建maven私有仓库

    使用nexus3.10搭建maven私有仓库-----详见如下链接-- --此贴用于笔记 https://blog.csdn.net/vipbupafeng/article/details/80232 ...

  6. 使用nexus搭建一个maven私有仓库

    使用nexus搭建一个maven私有仓库 大家好,我是程序员田同学.今天带大家搭建一个maven私有仓库. 很多公司都是搭建自己的Maven私有仓库,今天就带大家使用nexus搭建一个自己的私有仓库, ...

  7. 【图文并茂】 做开发这么久了,还不会搭建服务器Maven私有仓库?这也太Low了吧

    大家好,我是冰河~~ 最近不少小伙伴想在自己公司的内网搭建一套Maven私服环境,可自己搭建的过程中,或多过少的总会出现一些问题,问我可不可以出一篇如何搭建Maven私服的文章.这不,就有了这篇文章嘛 ...

  8. [maven] 使用Nexus创建maven私有仓库

    1.为什么需要maven私有仓库? 从Maven中央仓库下载所需的jar包,需要外网的支持.如果公司不能上外网的话则不能从中央仓库下载所需jar包,公司网速慢的时候也会影响项目构建的速度.用户可以用n ...

  9. 如何在云服务器创建maven私有仓库

    参考链接:https://blog.csdn.net/silence_jjj/article/details/77531916 nexus3创建maven私有仓库(windows) 1.官网:http ...

随机推荐

  1. vjudge-A-这是测试你会不会语言的模拟

    2017-07-14 18:13:35 writer:pprp 介绍:最基本用代码展示思想的一道题 题意如下; 他细细观察了自己的工作环境,发现整个工作室是一个N行M列的矩形布局,或者是因为屌丝的本性 ...

  2. winform中的ListBox和ComboBox绑定数据

    将集合数据绑定到ListBox和ComboBox控件,界面上显示某个属性的内容 //... //自定义了Person类(有Name,Age,Heigth等属性) List<Person> ...

  3. 轻量级 HTTP(s) 代理 TinyProxy

      J CentOS 下安装 TinyProxy yum install -y tinyproxy 启动.停止.重启 # 启动service tinyproxy start# 停止service ti ...

  4. tensorflow wide deep 介绍

    https://blog.csdn.net/heyc861221/article/details/80131369 https://blog.csdn.net/heyc861221/article/d ...

  5. 实例化后的list的默认值

    public class List默认值 { public static void main(String[] args) { List<String> arrayList = new A ...

  6. PHP XML Parser 函数

    PHP XML Parser 简介 XML 函数允许您解析 XML 文档,但无法对其进行验证. XML 是一种用于标准结构化文档交换的数据格式.您可以在我们的 XML 教程 中找到更多有关 XML 的 ...

  7. delphi ScriptGate 调用JS

    在 FireMonkey 使用 TWebBrowser 调用 Javascript函数并获取返回值以及 JavaScript 中调 Delphi 的函数/过程,普遍都在使用老掉牙的URL重定的方法,还 ...

  8. Android--------工具类StatusBarUtil实现完美状态栏

    很早就想写这篇博客了,直到前几天有人问我这方面的问题才想起. 沉浸式状态栏是从android Kitkat(Android 4.4)开始出现的,顶部状态栏的颜色可以根据开发需求改变,使得APP风格更加 ...

  9. 学习opencv(持续更新)

    redhat安装,报错解决方法 1 升级GCC,http://mirrors.kernel.org/gnu/gcc/ 2 更换稳定版本 #!/bin/bash yum -y install gcc g ...

  10. IPv6 地址分类

    IPv6本地链路地址 IPv6本地链路地址,类似于IPv4中APIPA(Automatic Private IP Addressing,自动专用IP寻址)所定义的地址169.254.0.0/16. I ...