maven 使用国内的资源库

 

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<!-- 阿里云仓库,使用国内maven 资源库 -->
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>

<!-- 中央仓库1 -->
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo1.maven.org/maven2/</url>
</mirror>

<!-- 中央仓库2 -->
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>
</mirrors>
</settings>html

 

eclipse设置maven加载国内镜像

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

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

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

        mac:eclipse偏好设置-》mavenspring

        而后选择 User Settings,以下图:apache

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

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

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

        windows须要在当前用户目录下,依管理员身份建立。spring-mvc

 

 

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

是的,你没看错,多出来了一个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
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包的惟一性。

 
分类:  eclipse
标签:  mavenaliyuneclipsemaven镜像
相关文章
相关标签/搜索