eclipse设置maven加载国内镜像
2015-09-10 10:39
459 查看
使用maven包管理器开发java web时,由于国内网速太慢,或者墙的缘故,创建project后,总是要等待很长时间加载所需jar包。这对于开发者而言,是一种痛苦的等待,对于企业,也是一种损失。
今天得遇高人指点,对eclipse中的maven插件做了优化配置,下面一步一步的操作示范,帮助有需要的朋友们:
linux/windows:打开eclipse后,window-》preferences-》maven
mac:eclipse偏好设置-》maven
然后选择 User Settings,如下图:
![](https://img-blog.csdn.net/20150910105102672?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
根据图中3的指示的位置,创建一个配置文件settings.xml。
linux/mac均可使用下面命令创建,先不写任何内容,然后保存,vim命令模式下是:wq,注:w是写入,q是退出,冒号是命令开始
接着回到eclipse的操作步骤,先关闭preferences面板,再次根据前面说步骤的,打开此面板,你会看到User Settings中发生的变化,如下图:
![](https://img-blog.csdn.net/20150910110255516?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
是的,你没看错,多出来了一个openfile。点击openfile,然后Apply,再OK,最后关闭此面板。此时,已经在eclipse编辑窗口打开了前面创建的settings.xml文件。
![](https://img-blog.csdn.net/20150910110830468?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
配置开始了,将下面的代码复制到settings.xml文件中,保存即可。
测试一下:在eclipse中创建一个maven工程,然后在eclipse的console窗口中,选择maven console。就可以看到加载的包的来源了。
![](https://img-blog.csdn.net/20150910111717284?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
右下角的倒三角箭头鼠标悬浮上去后,有很多console列表,选择maven console即,点击即可切换到maven窗口,可看到有关下载源的信息,如下图:
![](https://img-blog.csdn.net/20150910112134395?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
-------------------------------------------2015.10.8更新------------------------------------------------------------------------------
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
joyven@joyven-ThinkPad-E450:/mnt/workspace/spring-mvc$mvn archetype:generate DgroupId=joyven -DartifactId=spring-mvc -DarchetypeArtifactId=maven-archetype-webapp
修改之后则没有了。
补充一点:
用maven创建项目:
说明:maven主要依靠坐标来区分项目包。
groupId
artifactId
archetypeArtifactId
version
这四个值体现了maven包的唯一性。
今天得遇高人指点,对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.xmlwindows需要在当前用户目录下,依管理员身份创建。
接着回到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窗口,可看到有关下载源的信息,如下图:
-------------------------------------------2015.10.8更新------------------------------------------------------------------------------
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
joyven@joyven-ThinkPad-E450:/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包的唯一性。
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- 介绍一款信息管理系统的开源框架---jeecg
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- maven学习
- 插入排序
- 冒泡排序
- 堆排序
- 快速排序
- 二叉查找树