Maven入门系列(二)--设置中央仓库的方法
原文地址:http://www.codeweblog.com/maven入门系列-二-设置中央仓库的方法/
Maven仓库放在我的文档里好吗?当然不好,重装一次电脑,意味着一切jar都要重新下载和发布。
下载的地址是中央仓库mvnrepository.com,当然,全球很多个仓库。
资源的坐标简称GVA
那么,现在如何修改maven的本地仓库路径呢?
![]()
关键在于maven文件夹的config下的settings.xml(E:\IDE\apache-maven-3.3.1\conf\settings.xml)
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
这里的一段注释可以看到本地仓库默认在${user.home}/.m2/repository。
(本文出自:http://my.codeweblog.com/u/1156339/blog/396583)
如果在Linux下就是~/.m2/repository
现在如果要改动,就加入相应的标签。
<localRepository>E:\Java\maven\repos</localRepository>
现在我们再编译下次上一篇博客中的maven_2项目(依赖于maven_1项目的jar,原本已经发布到本体仓库):
E:\testspace\maven_2>mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maventest2 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-resources-plugin/2.6/maven-resources-plugin-2.6.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
resources-plugin/2.6/maven-resources-plugin-2.6.pom (8 KB at 3.4 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-plugins/23/maven-plugins-23.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
plugins/23/maven-plugins-23.pom (9 KB at 14.3 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/
22/maven-parent-22.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/2
2/maven-parent-22.pom (30 KB at 23.9 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/apache/11/apache-11
.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/apache/11/apache-11.
pom (15 KB at 14.3 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-resources-plugin/2.6/maven-resources-plugin-2.6.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
resources-plugin/2.6/maven-resources-plugin-2.6.jar (29 KB at 16.7 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-compiler-plugin/3.1/maven-compiler-plugin-3.1.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
compiler-plugin/3.1/maven-compiler-plugin-3.1.pom (10 KB at 6.6 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-plugins/24/maven-plugins-24.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
plugins/24/maven-plugins-24.pom (11 KB at 5.4 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/
23/maven-parent-23.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/2
3/maven-parent-23.pom (32 KB at 13.9 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/apache/13/apache-13
.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/apache/13/apache-13.
pom (14 KB at 12.7 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-compiler-plugin/3.1/maven-compiler-plugin-3.1.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
compiler-plugin/3.1/maven-compiler-plugin-3.1.jar (42 KB at 14.6 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/junit/junit/4.10/junit-4.10.po
m
Downloaded: https://repo.maven.apache.org/maven2/junit/junit/4.10/junit-4.10.pom
(3 KB at 2.1 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/hamcrest/hamcrest-core/1.1
/hamcrest-core-1.1.pom
Downloaded: https://repo.maven.apache.org/maven2/org/hamcrest/hamcrest-core/1.1/
hamcrest-core-1.1.pom (481 B at 0.3 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/hamcrest/hamcrest-parent/1
.1/hamcrest-parent-1.1.pom
Downloaded: https://repo.maven.apache.org/maven2/org/hamcrest/hamcrest-parent/1.
1/hamcrest-parent-1.1.pom (6 KB at 4.9 KB/sec)
[WARNING] The POM for com.happyBKs.maven:maventest:jar:0.0.1-SNAPSHOT is missing
, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21.691 s
[INFO] Finished at: 2015-04-06T16:51:35+08:00
[INFO] Final Memory: 10M/108M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project maventest2: Could not resolve dependen
cies for project com.happyBKs.maven:maventest2:jar:0.0.1-SNAPSHOT: Could not fin
d artifact com.happyBKs.maven:maventest:jar:0.0.1-SNAPSHOT -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyReso
lutionException E:\testspace\maven_2>
结果,又是一堆下载,因为本地仓库变了,所有的jar要重新下,如junit。但是由于新的本地仓库中没有maven_1项目的jar,所以编译报错。
这时候,我们将原先我的文档中大的默认本地仓库中的所有jar复制到新repos下。
![]()
这时候在编译一下
![]()
已经成功了!
第二个问题:我们如何设置我们线上的中央仓库。
在maven3.3.1文件夹下的lib下(E:\IDE\apache-maven-3.3.1\lib)有很多jar
其中有一个maven-model-builder-3.3.1.jar,用解压软件打开,org\apache\maven\model下有个pom-4.0.0.xml文件
![]()
打开该文件
<?xml version="1.0" encoding="UTF-8"?> <!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
--> <!-- START SNIPPET: superpom -->
<project>
<modelVersion>4.0.0</modelVersion> <repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories> <pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories> <build>
<directory>${project.basedir}/target</directory>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<finalName>${project.artifactId}-${project.version}</finalName>
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<scriptSourceDirectory>${project.basedir}/src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
<pluginManagement>
<!-- NOTE: These plugins will be removed from future versions of the super POM -->
<!-- They are kept for the moment as they are very unlikely to conflict with lifecycle mappings (MNG-4453) -->
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
</plugin>
</plugins>
</pluginManagement>
</build> <reporting>
<outputDirectory>${project.build.directory}/site</outputDirectory>
</reporting> <profiles>
<!-- NOTE: The release profile will be removed from future versions of the super POM -->
<profile>
<id>release-profile</id> <activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation> <build>
<plugins>
<plugin>
<inherited>true</inherited>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<inherited>true</inherited>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<inherited>true</inherited>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles> </project>
<!-- END SNIPPET: superpom -->
可以看到当中的中央仓库配置:
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
中央仓库地址是https://repo.maven.apache.org/maven2
如果用浏览器登录该url
![]()
就会找到中央仓库的搜索内容的来源
![]()
log4j、hibernate等都可以在这搜索到。
例如,我搜索hibernate
![]()
我选择一个点击
![]()
然后选一个版本,就可以看到
![]()
然后只要利用页面左侧的依赖描述复制下来,就可以使用了。
<dependency>
<groupId>hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.4.0.GA</version>
</dependency>
Maven入门系列(二)--设置中央仓库的方法的更多相关文章
- idea上使用maven入门(二)——本地仓库以及使用maven
本地仓库: 首先创建完一个项目之后,点击左上角file->setting(建一个文件夹repository,建议创建到maven的外面,主要如果maven需要换版本,方便管理)如下图: ma ...
- Maven学习系列二(1-5)
Maven学习系列二(1-5) 本文转自 QuantSeven 博客,讲解精炼易懂,适合入门,链接及截图如下 http://www.cnblogs.com/quanyongan/category/47 ...
- 清晰的教你如何将 Maven 项目上传至 中央仓库以及版本更新
项目中总会依赖一些大牛的开源库,例如 Android 开发 通过以下方式就可以方便的引入库.那么如何将我们自己的库也能这样来使用呢?下面我们将详细的讲解每一步的过程: implementation ' ...
- C# 互操作性入门系列(二):使用平台调用调用Win32 函数
好文章搬用工模式启动ing ..... { 文章中已经包含了原文链接 就不再次粘贴了 言明 改文章是一个系列,但只收录了2篇,原因是 够用了 } --------------------------- ...
- [转]C# 互操作性入门系列(二):使用平台调用调用Win32 函数
传送门 C#互操作系列文章: C# 互操作性入门系列(一):C#中互操作性介绍 C# 互操作性入门系列(二):使用平台调用调用Win32 函数 C# 互操作性入门系列(三):平台调用中的数据封送处理 ...
- mybatis入门系列二之输入与输出参数
mybatis入门系列二之详解输入与输出参数 基础知识 mybatis规定mapp.xml中每一个SQL语句形式上只能有一个@parameterType和一个@resultType 1. 返回 ...
- C语言高速入门系列(二)
C语言高速入门系列(二) -----转载请注明出处coder-pig 本节引言: 在前面一节中我们对C语言进行了初步的了解,学会了使用IDE进行代码的编写,编译执行! 在这一节中我们会对C语言的基本的 ...
- Java-Maven(八):IDEA使用本地maven,并配置远程中央仓库
声明:已经安装了maven,安装请参考:<Java-Maven(一):Maven的简介与安装> 1)一般我们从github.码云(https://gitee.com)上获取代码后,实际上我 ...
- Maven入门(二)pom.xml和核心概念
一.pom.xml文件说明 1.pom意思就是project object model. 2.pom.xml包含了项目构建的信息,包括项目的信息.项目的依赖等. 3.pom.xml文件是可以继承的,大 ...
随机推荐
- iOS NSDate获取当前时间并格式化
NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; [formatter setDateFormat:@"yyyy-MM- ...
- Android应用帧率--FPS测试
Android应用帧率FPS是衡量应用流畅度的一个非常重要的指标,可以根据FPS对应用做一些优化,那么在开发过程中如何来测试我们的应用的FPS呢? 准备工具:Eclipse + Android测试终端 ...
- 【原】iOS学习45之多媒体操作
1. 音频 1> 音频实现简述 iOS 里面共有四种专门实现播放音频的方式: System Sound Services(系统声音服务) OpenAL(跨平台的开源的音频处理接口) Audio ...
- yarn map failed
Container launch failed for container_1385017085286_4943_01_000053 : org.apache.hadoop.yarn.exceptio ...
- topcoder SRM 623 DIV2 CatAndRat
解决本题的一个关键点就是当Cat进入时,此时Rat在哪个位置? 注意移动方向可以随时改变,由于是圆环,故离入口最远点的距离是pi*R,即圆的一半, 当cat进入时(cat的速度大于rat的速度,否则不 ...
- ACM: CodeForces 140A New Year Table-数学几何
CodeForces 140A New Year Table Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d ...
- 10秒钟安装 Vim编辑器,5分钟浏览常用命令 2015.10.25
首先我想说,vim与vi的命令几乎相同,,所以学习编辑命令时很轻松,排除扩展相关,以及自动补全等配置的使用在外30秒钟安装 Vim编辑器,5分钟浏览常用命令环境:虚拟机Ubuntu:安装vim并浏览命 ...
- Code[VS]1690 开关灯 题解
Code[VS]1690 开关灯 题解 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description: YYX家门前 ...
- 【BZOJ】3211: 花神游历各国
题意 \(n\)个点,第\(i\)个点值为\(a_i\).\(m\)个询问,每次询问\([l, r]\)内的和或者将\([l, r]\)的每个值改为自己的算术平方根.(\(n \le 100000, ...
- 求1+2+……+n(位运算)
求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C). 我发现网上的做法都很神,各种理由编译的巧妙办法,就能间接 ...