通过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. Navicat Premium Mac破解版安装方法

    第一步:这部分暂时存到文本编辑器中 公钥: -----BEGIN PUBLIC KEY-----MIIBITANBgkqhkiG9w0BAQEFAAOCAQ4AMIIBCQKCAQB8vXG0ImYh ...

  2. scrapy实战4 GET方法抓取ajax动态页面(以糗事百科APP为例子):

    一般来说爬虫类框架抓取Ajax动态页面都是通过一些第三方的webkit库去手动执行html页面中的js代码, 最后将生产的html代码交给spider分析.本篇文章则是通过利用fiddler抓包获取j ...

  3. spring的context:exclude-filter 与 context:include-filter

    1 在主容器中(applicationContext.xml),将Controller的注解打消掉 <context:component-scan base-package="com& ...

  4. Centos7 防护墙 设置端口

    Centos7中的防火墙调整为firewalld,试一下systemctl stop firewalld关闭防火墙. 命令:systemctl stop firewalld 命令:systemctl ...

  5. [Lydsy2017年4月月赛]抵制克苏恩题解

    考试的时候以为就是简单的概率期望题,考完后知道是简单的概率期望DP题,完美爆零. 这道题数据范围很小,很容易让人想到状压,不过貌似没什么可压的.那么只能说明这道题复杂度很高了,状态数组f[o][i][ ...

  6. C语言指针专题——使用指针要注意这些

    本文为原创,欢迎转发: 欢迎关注微博与微信号:C语言编程技术分享 C语言中,指针的概念有点难懂,使用起来稍微不注意,也会遇到各种问题.在本文中,我列举出了几个使用指针不当的方式,希望朋友们在编程实践中 ...

  7. [WPF自定义控件库]了解WPF的布局过程,并利用Measure为Expander添加动画

    1. 前言 这篇文章介绍WPF UI元素的两步布局过程,并且通过Resizer控件介绍只使用Measure可以实现些什么内容. 我不建议初学者做太多动画的工作,但合适的动画可以引导用户视线,提升用户体 ...

  8. k8s学习 - 概念 - Deployment

    k8s学习 - 概念 - Deployment 有了 ReplicaSet 还需要有 Deployment 的原因是希望有一个控制器能管理部署更新时候的版本控制问题.一个 Deployment 可以管 ...

  9. kali linux上安装ssh

    1.暂停kali上的ssh进程 root@kali:~# sudo stop ssh 2.卸载ssh服务 root@kali:~# apt-get remove openssh-server 这里可能 ...

  10. 创建PaletteSet的一个问题

    下面是一个常规创建PaletteSet面板的代码: public static PaletteSet m_ps = null; [CommandMethod("MyPalette" ...