通过Internet直接从Maven公用仓库获取依赖包是默认配置。不过对于中国软件公司来讲,访问这些公用仓库通常较慢,对于一些管理严格的不能直接上网的软件公司来讲,这更加是不可能的。Maven项目可以配置成仅从Maven私服上获取依赖。

上一篇已经讲述了如何安装Nexus为Maven私服。下面就假定使用S1服务器上的Nexus服务。可以参考官方文档:

http://www.sonatype.com/books/nexus-book/reference/config-sect-intro.html

在开发机器上有Maven项目,首先编辑~/.m2/settings.xml.

  1. <settings>
  2. <mirrors>
  3. <mirror>
  4. <!--This sends everything else to /public -->
  5. <id>nexus</id>
  6. <mirrorOf>*</mirrorOf>
  7. <url>http://S1:8081/nexus/content/groups/public</url>
  8. </mirror>
  9. </mirrors>
  10. <profiles>
  11. <profile>
  12. <id>nexus</id>
  13. <!--Enable snapshots for the built in central repo to direct -->
  14. <!--all requests to nexus via the mirror -->
  15. <repositories>
  16. <repository>
  17. <id>central</id>
  18. <url>http://central</url>
  19. <releases><enabled>true</enabled></releases>
  20. <snapshots><enabled>true</enabled></snapshots>
  21. </repository>
  22. </repositories>
  23. <pluginRepositories>
  24. <pluginRepository>
  25. <id>central</id>
  26. <url>http://central</url>
  27. <releases><enabled>true</enabled></releases>
  28. <snapshots><enabled>true</enabled></snapshots>
  29. </pluginRepository>
  30. </pluginRepositories>
  31. </profile>
  32. </profiles>
  33. <activeProfiles>
  34. <!--make the profile active all the time -->
  35. <activeProfile>nexus</activeProfile>
  36. </activeProfiles>
  37. </settings>
只需要把S1改成自己的Nexus服务器地址就可以了。如果你的Maven项目的pom.xml中没有自定义的repository,那么就可以使用了。比如执行mvn clean compile命令,就可从S1上下载pom.xml和jar包。
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://172.27.2.203:8081/nexus/content/groups/public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
</repository>
</repositories> <pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://172.27.2.203:8081/nexus/content/groups/public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>

注意,有时候nexus上已经部署了最新的snapshot,但是mvn clean compile就是不取最新版本,这时候需要用-U 参数强制检查。

mvn clean compile -U

如果还不行,则删除本地缓存的目录,在jenkins项目中可以在build之前执行一行命令,比如:

  1. rm -rf /usr/share/tomcat7/.m2/repository/com/esri/carrier/nginx-factory/

从Maven私服获取依赖的更多相关文章

  1. 将Android封装库通过gradle部署到maven私服并依赖使用

    一.在需要发布的模块chrisbaselibrary下的build.gradle中添加以下部分 //maven插件 apply plugin: 'maven' //打包main目录下代码和资源的 ta ...

  2. Maven 私服的简单使用

    所有的 Java 开发者应该是没有没用过 Maven 的吧.Maven 作为 Java 项目管理工具,它不仅可以用作包管理,还有许多的插件,可以支持整个项目的开发.打包.测试.部署等一系列行为.而包管 ...

  3. maven 私服同步无法获取依赖的pom.xml的依赖

    项目中引入了依赖: <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hado ...

  4. maven仓库总结,maven私服搭建

    配置pom.xml依赖包时在这里找包的描述: http://search.maven.org/#browse 以java为根目录. mvn archtype:generate -DgroupId=zt ...

  5. 搭建Maven私服那点事

    摘要:本文主要介绍在CentOS7.1下使用nexus3.6.0搭建maven私服,以及maven私服的使用(将自己的Maven项目指定到私服地址.将第三方项目jar上传到私服供其他项目组使用) 一. ...

  6. [Gradle系列]Gradle发布module库到jCenter, 并构建自己的企业Maven私服

    Tamic 作者: http://blog.csdn.net/sk719887916/article/details/53224544 前言 andorid开发者经常会看到xx公司发布了xx项目,xx ...

  7. window Maven私服搭建——nexus

    注:本文来源于 <window   Maven私服搭建--nexus> Maven私服搭建--nexus 1.下载nexus https://www.sonatype.com/downlo ...

  8. Maven的下载,安装,配置,测试,初识以及Maven私服

    :Maven目录分析 bin:含有mvn运行的脚本 boot:含有plexus-classworlds类加载器框架 conf:含有settings.xml配置文件 lib:含有Maven运行时所需要的 ...

  9. Anroid 搭建Maven私服(Android Studio)

    一.场景 ① 公司中有多个项目,多人开发,开发中的某一模块需要被其他几个项目的模块所依赖,最简单粗暴的方式就是打包成aar或者jar文件逐个拷贝到libs下进行依赖,可是这种方式太过于麻烦,而且需要每 ...

随机推荐

  1. 02(a)多元无约束优化问题

    2.1 基本优化问题 $\operatorname{minimize}\text{    }f(x)\text{       for   }x\in {{R}^{n}}$ 解决无约束优化问题的一般步骤 ...

  2. 对于springboot的几种注入方法的个人看法

    最近在知乎上面看到一篇关于程序员面试的问题,面试官问我们一般有几种注入的方法,这几种注入的方法分别在什么时候运用比合理,当时我看到这个时候懵逼了,由于我自己也是刚刚接触springboot不久,所以就 ...

  3. MyBatis bind标签的用法

    From<MyBatis从入门到精通> <!-- 4.5 bind用法 bind标签可以使用OGNL表达式创建一个变量并将其绑定到上下文中. 需求: concat函数连接字符串,在M ...

  4. [HDU4135]CO Prime(容斥)

    也许更好的阅读体验 \(\mathcal{Description}\) \(t\)组询问,每次询问\(l,r,k\),问\([l,r]\)内有多少数与\(k\)互质 \(0<l<=r< ...

  5. 安卓BindService笔记

    1 前言 最近学习到了安卓的service,记录一下自己对BindService的理解,学习教程以及部分代码来自菜鸟教程的android教程:菜鸟教程安卓端BindService链接 2 正文 先贴一 ...

  6. docker原理介绍

    内部分享的ppt,做的有些粗糙... 个人使用的总结,如有错误,多多指正!

  7. PC端触底效果反复触发的解决方案

    最近在做一个PC端的项目,要求是在滑动到页面的底部的时候就动态的加载下一页的数据,代码实现思路如下: 首先,我们需要知道浏览器中有三个高度,分别是屏幕高度(outerHeight),文档容器高度(in ...

  8. bean的创建(五)第二部分 寻找bean的工厂方法实例化

    instanceWrapper = createBeanInstance(beanName, mbd, args); AbstractAutowireCapableBeanFactory.create ...

  9. 主机cpu突然飙高,如何快速排查问题

    [问题发现] 使用zabbix软件监控服务器时发现cpu突然异常,在业务主机上使用top命令查看系统的整体运行情况,使用top命令后发现mysqld占用CPU特别高,初步判断可能是mysqld出现问题 ...

  10. Promise异步编程解决方案

    Promise是ES6中新增的异步编程解决方案,体现在代码中它是一个对象,可以通过 Promise 构造函数来实例化. 其最基本的使用 new Promise(function(resolve,rej ...