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. SDWebImage源代码解析(二)

    上一篇:SDWebImage源代码解析(一) 2.缓存 为了降低网络流量的消耗.我们都希望下载下来的图片缓存到本地.下次再去获取同一张图片时.能够直接从本地获取,而不再从远程server获取.这样做的 ...

  2. UI各种小控件的用法

    今天给大家列举出来UI中的一些小控件的用法.方便大的学习与使用 一些方法和属性我们能够查看API文档.不必将每一个控件的功能都记住, 由于在使用的过程中,我们能够查看API文档.方便使用,我们仅仅要记 ...

  3. 基于lucene的案例开发:纵横小说分布式採集

    转载请注明出处:http://blog.csdn.net/xiaojimanman/article/details/46812645 http://www.llwjy.com/blogdetail/9 ...

  4. mysql安装出错cannot create windows service for mysql.error:0

    配置时最后一步出现不能启动mysql 解决成功的办法:[MySQL] Could not start the service MySQL 解决方法 安装mysql 5.1.33,在运行Server I ...

  5. MongodDB用GridFS方式存取文件

    在实现GridFS方式前我先讲讲它的原理,为什么可以存大文件.驱动首先会在当前数据库创建两个集合:"fs.files"和"fs.chunks"集合,前者记录了文 ...

  6. Codeforces Round #316 (Div. 2)E. Pig and Palindromes DP

    E. Pig and Palindromes   Peppa the Pig was walking and walked into the forest. What a strange coinci ...

  7. 2017-3-4 leetcode 414 485 495

    虽说周末要早起来着,但是日子过得有点奇怪,一不小心就忘掉了... leetcode414 https://leetcode.com/problems/third-maximum-number/?tab ...

  8. 12. Integer to Roman[M]整数转罗马数字

    题目 Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from ...

  9. POJ 2388 基数排序

    这题可以直接nth_element过去 比如这样子 //By SiriusRen #include <cstdio> #include <algorithm> using na ...

  10. bootstrap在input框中加入icon图标

    <form class="form-horizontal"> <div class="form-group has-feedback"> ...