Eclipse配置Maven私服

前言

搭建Maven私有仓库的主要目的,是为了在团队多人开发时,只要内网的私有仓库有下载过依赖的jar包,就直接从私有仓库获取,不再通过外网的中央仓库。如果私服上面没有,就通过私服上面的索引到中央仓库中缓存到私服中。

配置方式:

Eclipse配置Maven私服有两种,一种是在pom.xml里面配置,只针对pom所在的工程;另一种是在Eclipse安装目录中的setting.xml中配置,这是针对Eclipse中所有工程;

一、配置私服的位置(从私服中下载jar);

1、 pom.xml中配置:

在pom.xml中的<project>中加入如下配置

1.    <repositories>
2. <repository>
3. <id>nexus</id>
4. <name>nexus</name>
5. <url>http://192.168.100.52:8081/nexus/content/groups/public/</url>
6. <releases>
7. <enabled>true</enabled>
8. </releases>
9. <snapshots>
10. <enabled>true</enabled>
11. </snapshots>
12. </repository>
13. </repositories>

url指向本地私服的仓库组,并启用了releases库(稳定版本库)以及snapshots(开发版本库);其实我们的仓库组中除了包含了这两个库之外还包含了第三方库(3rd parth)以及中央库(central);

2、setting.xml中配置:

setting中配置要比pom麻烦多一点,不过毕竟人家是针对eclipse中的所有工程:

先在<servers>标签中添加私服的权限

14.    <server>
15. <id>nexus-releases</id>
16. <username>admin</username>
17. <password>admin123</password>
18. </server>
19. <server>
20. <id>nexus-snapshots</id>
21. <username>admin</username>
22. <password>admin123</password>
23. </server>

这里的权限是用于上传jar到私服的;

接下来继续在setting.xml找到<mirrors>标签,我们来配置一下私服的镜像:

24.    <mirror>
25. <id>nexus-releases</id>
26. <mirrorOf>*</mirrorOf>
27. <url>http://192.168.100.52:8081/nexus/content/groups/public/</url>
28. </mirror>
29. <mirror>
30. <id>nexus-snapshots</id>
31. <mirrorOf>*</mirrorOf>
32. <url>http://192.168.100.52:8081/nexus/content/repositories/snapshots/</url>
33. </mirror>

这里的id与前面的权限的id其实……没什么关系。

接下来继续找到<profiles>标签,开始配置私服:

34.    <profile>
35. <id>nexus</id>
36. <repositories>
37. <repository>
38. <id>nexus-releases</id>
39. <name>Nexus</name>
40. <url>http://nexus-releases</url> <!—这里要引入上面的镜像-->
41. <releases>
42. <enabled>true</enabled>
43. <updatePolicy>never</updatePolicy>
44. <checksumPolicy>warn</checksumPolicy>
45. </releases>
46. <snapshots>
47. <enabled>true</enabled>
48. </snapshots>
49. </repository>
50. <repository>
51. <id>nexus-snapshots</id>
52. <name>Nexus</name>
53. <url>http://nexus-snapshots</url> <!—同样引入上面的镜像-->
54. <releases>
55. <enabled>true</enabled>
56. <updatePolicy>never</updatePolicy>
57. <checksumPolicy>warn</checksumPolicy>
58. </releases>
59. <snapshots>
60. <enabled>true</enabled>
61. </snapshots>
62. </repository>
63. </repositories>
64. <pluginRepositories> <!—同样是插件的配置-->
65. <pluginRepository>
66. <id>nexus-releases</id>
67. <name>Nexus</name>
68. <url>http://nexus-releases</url> <!—同样引入上面的镜像-->
69. <snapshots>
70. <enabled>true</enabled>
71. <updatePolicy>never</updatePolicy>
72. <checksumPolicy>warn</checksumPolicy>
73. </snapshots>
74. <releases>
75. <enabled>true</enabled>
76. </releases>
77. </pluginRepository>
78. <pluginRepository>
79. <id>nexus-snapshots</id>
80. <name>Nexus</name>
81. <url>http://nexus-snapshots</url> <!—同样引入上面的镜像-->
82. <snapshots>
83. <enabled>true</enabled>
84. <updatePolicy>never</updatePolicy>
85. <checksumPolicy>warn</checksumPolicy>
86. </snapshots>
87. <releases>
88. <enabled>true</enabled>
89. </releases>
90. </pluginRepository>
91. </pluginRepositories>
92. </profile>

最后,根据配置id激活这些配置,

93.     <activeProfiles>
94. <activeProfile>nexus</activeProfile>
95. </activeProfiles>

当然,如果你是新建一个setting.xml的话,要在eclipse里面更改setting.xml的路径,指向你新建的setting.xml

Window->Prederences ->Maven -> User Settings

二、上传jar到私服:

如果工程编译出的jar包要上传到私服,那就要在要上传的工程的pom.xml中的<project>下,增加

1.    <distributionManagement>
2. <repository>
3. <id>nexus-releases</id>
4. <name>Nexus</name>
5. <url>http://192.168.100.52:8081/nexus/content/repositories/releases/</url>
6. </repository>
7. <snapshotRepository>
8. <id>nexus-snapshot</id>
9. <name>Nexus</name>
10. <url>http://192.168.100.52:8081/nexus/content/repositories/snapshots/</url>
11. </snapshotRepository>
12. </distributionManagement>

上传时,右键项目Run As->Run Configurations->Maven Build

注:deploy后面的-e可以省略

扩展:

1、设置Maven的本地缓存:

Maven的本地缓存一般默认都是在C盘,这就有点让人难以接受了,不过还好,可以在setting.xml中配置一下缓存的位置:

<localRepository>D:\maven</localRepository>

2、配置在eclipse中配置jdk:

可以在setting.xml中的可以配置一下默认的jdk版本,这样就不用每个项目都去指定jdk的版本了

14.    <profile>
15. <id>jdk-1.8</id>
16. <activation>
17. <activeByDefault>true</activeByDefault>
18. <jdk>1.8</jdk>
19. </activation>
20. <properties>
21. <maven.compiler.source>1.8</maven.compiler.source>
22. <maven.compiler.target>1.8</maven.compiler.target>
23. <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
24. </properties>
25. </profile>

Eclipse配置Maven私服的更多相关文章

  1. 【项目管理和构建】十分钟教程,eclipse配置maven + 创建maven项目(三)

    [项目管理和构建]十分钟教程,eclipse配置maven + 创建maven项目(三) 上篇博文中我们介绍了maven下载.安装和配置(二),这篇博文我们配置一下eclipse,将它和maven结合 ...

  2. eclipse配置maven + 创建maven项目(三)

    上篇博文中我们介绍了maven下载.安装和配置(二),这篇博文我们配置一下eclipse,将它和maven结合,并我们创建一个maven的项目. 准备工作 在eclipse配置maven之前需要我们做 ...

  3. Eclipse配置maven环境

    一.什么是maven? Maven是一个项目管理工具,它包含了一个项目对象模型 (Project Object Model),一组标准集合,一个项目生命周期(Project Lifecycle),一个 ...

  4. Eclipse配置maven环境1

    一.什么是maven? Maven是一个项目管理工具,它包含了一个项目对象模型 (Project Object Model),一组标准集合,一个项目生命周期(Project Lifecycle),一个 ...

  5. Eclipse 配置Maven

    Eclipse 配置Maven 下载Maven 首先在官网下载Maven:http://maven.apache.org/download.cgi 下载后将其解压到相应的位置 配置Maven环境变量 ...

  6. Mac中Eclipse配置Maven开发环境

    1.下载Maven tar.gz包 http://maven.apache.org/download.cgi 2.解压tar包 随便一个路径都行 3.配置环境变量 bash设置~/.bash_prof ...

  7. eclipse配置maven + 创建maven项目

        登录|注册     努力+坚持,而且还很年轻   目录(?)[+] 在现实的企业中,以低成本.高效率.高质量的完成项目,不仅仅需要技术大牛,企业更加需要管理大牛,管理者只懂技术是远远不够的.当 ...

  8. Eclipse配置Maven开发环境

    前言: 现在Eclipse版本越来越高.高版本的Eclipse甚至已经集成了Maven像是SpringSource的哪个版本.用习惯了Eclipse.在开发中还是不想更换掉自己的IDE.如此一来就又了 ...

  9. Eclipse 安装Maven以及Eclipse配置Maven

    安装Maven 1 下载 Downloading Apache Maven 3.5.0 选择 2 解压 3 配置环境变量 新建变量名:MAVEN_HOME  变量值:D:\SoftwareInstal ...

随机推荐

  1. [React Router] Prevent Navigation with the React Router Prompt Component

    In this lesson we'll show how to setup the Prompt component from React Router. We'll prompt with a s ...

  2. android 九宫格(16宫格)控件

    public class NineRectView extends ViewGroup { private Context ctx; private int wSize,hSize,row,colum ...

  3. mbed

    mbed介绍--ARM最新面向IOT的RTOS与平台 文章为本人原创,转载请注明:http://blog.csdn.net/guo8113/article/details/40479303 mbed是 ...

  4. 小P寻宝记——好基友一起走

    小P寻宝记--好基友一起走 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述 话说.上次小P到伊利哇呀国旅行得到了一批宝藏.他是 ...

  5. hdu 5031 Lines 爆搜

    事实上嘞,这个线能够仅仅延伸一端 然后嘞,爆搜一次就能够 最后嘞,600-800ms过 本弱就是弱啊.你来打我呀-- #include<iostream> #include<cstr ...

  6. log4j日志存储到数据库

    一.前提条件 系统必须是使用LOG4J进行日志管理,否则方法无效. 系统必须包含commons-logging-xxx.jar,log4j-xxx.jar这两个JAR包,XXX为版本号. 二.操作步骤 ...

  7. 0x02 枚举、模拟、递推

    1.TYVJ1266(这站是不是已经倒闭了啊) USACO陈年老题,对于这种开关问题啊,最多只按一次,而且第一行随便按完下面的就全确定了,类似的还有固定翻转一个长度的区间,这个也是最多翻一次的而且翻的 ...

  8. Swift 实践之UIWebView

    1.选中工程,点击右键,New File>在iOS下选中Othe>Empty,生成一个.js的脚本文件,将代码粘贴过去保存; var script = document.createEle ...

  9. BZOJ 4004 高斯消元

    思路: 排个序 消元 完事~ 但是! 坑爹精度毁我人生 我hhhh他一脸 红红火火恍恍惚惚 //By SiriusRen #include <cmath> #include <cst ...

  10. Python 函数(一)

      定义一个函数 函数的第一行语句可以选择性地使用文档字符串—用于存放函数说明. 函数内容以冒号起始,并且缩进. return [表达式] 结束函数,选择性地返回一个值给调用方.不带表达式的retur ...