通过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. ajax 前端发含有列表的数据

    在前端页面也可以给后端发送一个包含列表的数据 html <body> <h3>index页面 </h3> <input type="text&quo ...

  2. 使用@Transactional注意的问题

    @Transactional 基本原理概述 在应用系统调用声明@Transactional 的目标方法时,Spring Framework 默认使用 AOP 代理,在代码运行时生成一个代理对象,根据@ ...

  3. ueditor 常用配置

    scaleEnabled:是否可以拉伸长高,默认true(当开启时,自动长高失效) autoHeightEnabled:是否自动长高,默认true catchRemoteImageEnable:设置远 ...

  4. Git使用小技巧之免密登录

    想要获取更多文章可以访问我的博客 - 代码无止境. 小代同学在使用Git的过程中发现,每次向远程仓库推送代码的时候都需要输入账号密码.做为一个程序员,多多少少都会有偷懒的思维.那么如何才能避免每次都要 ...

  5. 性能测试-实例讲解VU、RPS、RT公式换算

    概述 今天看到一篇文章讲解VU.RPS.RT,中间有一个公式如下图 并发数 = RPS * 响应时间  于是我在本地做了几次实验,试图验证一下公式的准确性 实验网站 www.baidu.com 第一次 ...

  6. 算法学习笔记,几个简单的Demo

    算法初学的一些心得 前言:现在工作也快一年多了,有时间下班回家会学学算法,陆陆续续也接触了一些 貌似我知道的就冒泡排序其他的都不是很了解 最近买了一本书,边学边记录吧! 一些常用的方法 暴力破解 下面 ...

  7. Netty-解码器架构与常用解码器

    任何数据类型想在网络中进行传输,都得经过编解码转换成字节流 在netty中,服务端和客户端进行通信的其实是下面这样的 程序 ---编码--> 网络 网路 ---解码--> 程序 对应服务端 ...

  8. 个人永久性免费-Excel催化剂功能第75波-标签式报表转标准数据源

    数据处理永远是数据分析工作中重中之重的任务,大部分人深深地陷入在数据处理的泥潭中,今天Excel催化剂再接再厉,在过往已提供了主从结构报表数据源的数据转换后,再次给大家送上标签式报表数据源的数据转换操 ...

  9. HBase的优化

    HBase的优化 高可用 在 HBase 中 Hmaster 负责监控 RegionServer 的生命周期,均衡 RegionServer 的负载,如果 Hmaster 挂掉了,那么整个 HBase ...

  10. sql format 格式化数字(前面补0)

    将一个数字例如33,或1使用t-sql语句转换成033或001 以下是详细分析: 1.select power(10,3)得到1000 2.select cast(1000+33 as varchar ...