eclipse设置maven加载国内镜像

使用maven包管理器开发java web时,由于国内网速太慢,或者墙的缘故,创建project后,总是要等待很长时间加载所需jar包。这对于开发者而言,是一种痛苦的等待,对于企业,也是一种损失。

今天得遇高人指点,对eclipse中的maven插件做了优化配置,下面一步一步的操作示范,帮助有需要的朋友们:

linux/windows:打开eclipse后,window-》preferences-》maven

mac:eclipse偏好设置-》maven

然后选择 User Settings,如下图:

根据图中3的指示的位置,创建一个配置文件settings.xml。

linux/mac均可使用下面命令创建,先不写任何内容,然后保存,vim命令模式下是:wq,注:w是写入,q是退出,冒号是命令开始

     ~$ vim /home/joyven/.m2/settings.xml

windows需要在当前用户目录下,依管理员身份创建。

接着回到eclipse的操作步骤,先关闭preferences面板,再次根据前面说步骤的,打开此面板,你会看到User Settings中发生的变化,如下图:

是的,你没看错,多出来了一个openfile。点击openfile,然后Apply,再OK,最后关闭此面板。此时,已经在eclipse编辑窗口打开了前面创建的settings.xml文件。

配置开始了,将下面的代码复制到settings.xml文件中,保存即可。

<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
	<mirrors>
		<!-- mirror | Specifies a repository mirror site to use instead of a given
			repository. The repository that | this mirror serves has an ID that matches
			the mirrorOf element of this mirror. IDs are used | for inheritance and direct
			lookup purposes, and must be unique across the set of mirrors. | -->
		<mirror>
			<id>nexus-osc</id>
			<mirrorOf>central</mirrorOf>
			<name>Nexus osc</name>
			<url>http://maven.oschina.net/content/groups/public/</url>
		</mirror>
		<mirror>
			<id>nexus-osc-thirdparty</id>
			<mirrorOf>thirdparty</mirrorOf>
			<name>Nexus osc thirdparty</name>
			<url>http://maven.oschina.net/content/repositories/thirdparty/</url>
		</mirror>
	</mirrors>

	<profiles>
		<profile>
			<id>default</id>
			<repositories>
				<repository>
					<id>nexus</id>
					<name>local private nexus</name>
					<url>http://maven.oschina.net/content/groups/public/</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>false</enabled>
					</snapshots>
				</repository>
			</repositories>
			<pluginRepositories>
				<pluginRepository>
					<id>nexus</id>
					<name>local private nexus</name>
					<url>http://maven.oschina.net/content/groups/public/</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>false</enabled>
					</snapshots>
				</pluginRepository>
			</pluginRepositories>
		</profile>
	</profiles>
</settings>

测试一下:在eclipse中创建一个maven工程,然后在eclipse的console窗口中,选择maven console。就可以看到加载的包的来源了。

右下角的倒三角箭头鼠标悬浮上去后,有很多console列表,选择maven console即,点击即可切换到maven窗口,可看到有关下载源的信息,如下图:

-------------------------------------------补充更新------------------------------------------------------------------------------

settings.xml文件中,在标签<profile>必须包含在<profiles>中,否则在使用命令行执行mvn时,会出现一些错误:

Error reading settings.xml: Unrecognised tag: ‘profile‘ (position: START_TAG seen ...</mirrors>\n\n\t<profile>... @22:11) 
  Line:   22
  Column: 11
[email protected]:/mnt/workspace/spring-mvc$ mvn archetype:generate DgroupId=joyven -DartifactId=spring-mvc -DarchetypeArtifactId=maven-archetype-webapp

修改之后则没有了。

补充一点:

用maven创建项目:

 mvn archetype:generate DgroupId=joyven -DartifactId=spring-mvc -DarchetypeArtifactId=maven-archetype-webapp

说明:maven主要依靠坐标来区分项目包。

groupId

artifactId

archetypeArtifactId

version

这四个值体现了maven包的唯一性。

时间: 2024-07-31 04:18:15

eclipse设置maven加载国内镜像的相关文章

MAVEN加载国内阿里云镜像

转载学习链接 https://yq.aliyun.com/articles/6861  感谢干货,记录下. 安装maven包后,有一个默认的 settings.xml文件,在<mirrors>添加子标签,代码如下 1 <mirror> 2 <id>alimaven</id> 3 <name>aliyun maven</name> 4 <url>http://maven.aliyun.com/nexus/content/gr

解决IDEA中Maven加载依赖包慢的问题

原理:maven加载jar包过程,默认的是先扫描本地仓库,若本地仓库没有,则扫描远程仓库下载.默认的conf/settings.xml文件没有配置远程仓库,所以扫描的是maven的中央仓库(在国外),所以慢. 解决方法:配置国内镜像(如阿里云的镜像) 修改conf/settings.xml文件,配置阿里云镜像代码 1 <mirrors> 2 <!-- mirror 3 | Specifies a repository mirror site to use instead of a giv

Android 编程之天气预报闹钟启动服务设置界面加载--4

真个application讲的已经差不多了,在说完这一篇之后,我会上传源码到资源,喜欢的可以下载和学习,今天主讲闹钟启动设置,设置页面的加载 在Android系统中,闹钟和唤醒功能都是由Alarm Manager Service控制并管理的.我们所熟悉的RTC闹钟以及定时器都和它有莫大的关系.为了便于称呼,我常常也把这个service简称为ALMS.         另外,ALMS还提供了一个AlarmManager辅助类.在实际的代码中,应用程序一般都是通过这个辅助类来和ALMS打交道的.就代

Android系统定制——Download Android System 及加载system镜像文件

定制android系统(配置及相关系统的镜像文件),具体可参考:Driver_All_in_One_V1.0--MT6735_6753.pdf文档,特别需要理解的是Download部分. 与之对应的软件是:Smart Phone Flash Tool,一般是在菜单栏的Download部分进行选择操作. Download-agent(下载代理):选择 \升级固件与升级固件的工具\SP_Flash_Tool_exe_Windows_v5.1536.00.000 文件(通常不用特别选择,使用默认的即可

PHP中使用set_include_path动态设置文件加载扫描路径

/index.php/include/config.php 下面是index.php <?php  $path = '/usr/lib/pear';  set_include_path(get_include_path() . PATH_SEPARATOR . $path); //设置后的include_path变为类似/usr/lib/function;/usr/lib/pear  include("config.php"); //先搜索当前目录->搜索get_inclu

【转】Selenium2(WebDriver)总结(一)---启动浏览器、设置profile&amp;加载插件

基本读踩过的坑,泪流满面··· 本文主要记录下在使用selenium2/webdriver时启动各种浏览器的方法.以及如何加载插件.定制浏览器信息(设置profile)等 环境搭建可参考我的另一篇文章:http://www.cnblogs.com/puresoul/p/3483055.html 一.Driver下载地址: http://docs.seleniumhq.org/download/ 二.启动firefox浏览器(不需要下载驱动,原生支持) 1.firefox安装在默认路径下: 1 /

hibernate 设置懒加载自动为字段添加属性

hibernate错误:org.apache.struts2.json.JSONWriter can not access a member of class org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper with modifiers "public" 解释是当action执行完,return success返回xml文件后,前提是你设置了懒加载之后,hibernate自动为你懒加载的实

使用Maven加载项目有Dubbo框架时出现的常见异常情况

异常描述: The matching wildcard is strict, but no declaration can be found for element 'dubbo:reference' Multiple annotations found at this line: - schema_reference.4: Failed to read schema document 'http://code.alibabatech.com/schema/dubbo/dubbo.xsd', b

Selenium2(WebDriver)总结(一)---启动浏览器、设置profile&amp;加载插件

本文主要记录下在使用selenium2/webdriver时启动各种浏览器的方法.以及如何加载插件.定制浏览器信息(设置profile)等 环境搭建可参考我的另一篇文章:http://www.cnblogs.com/puresoul/p/3483055.html 一.Driver下载地址: http://docs.seleniumhq.org/download/ 二.启动firefox浏览器(不需要下载驱动,原生支持) 1.firefox安装在默认路径下: 1 //启动默认安装路径下的ff 2