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文件是可以继承的,大 ...
 
随机推荐
- Js图片切换
			
<!DOCTYPE html><html<head> <meta charset="UTF-8"> <title></t ...
 - 一个android样本的过保护
			
前段时间处理一个android样本,样本本身作用不大,但是加了保护,遂做一个过保护的记录 通过dex2jar将dex转为jar文件的时候发现无法成功,通过抛出的异常可知,此处MainActivity: ...
 - psql-04数据类型(2)
			
复合类型 PostgreSQL中可以如C语言中的结构体一样定义一个复合类型; 创建 create type person as ( name text, age int, sex boolean ); ...
 - WPF中获取形状范围
			
在没加入到Canvas时,也能获取形状的方法: var polygon = new Polygon(); polygon.Points.Add(new Point(xStart, yStart)); ...
 - c# 修饰词public, protected, private,internal,protected的区别
			
public: 对任何类和成员都公开, 无限制访问;protected: 仅仅对该类以及该类的派生类公开;private: 仅仅对该类公开;internal: 只能值包含该类的程序集中访问该类(只是 ...
 - uva 11636
			
#include <cstdio> #include <cstring> #include <iostream> using namespace std; int ...
 - HDU5823 : color II
			
每种颜色的点集肯定是独立集,因此可以通过$O(2^n)$枚举每个集合判断出每个集合是否只需要一种颜色即可染色. 设$f[i][S]$表示$i$种颜色覆盖$S$这个集合的方案数,假定两个集合可以相交,那 ...
 - Java NIO非阻塞理论学习
			
Java NIO和阻塞IO的区别: 阻塞I/O在调用InputStream.read()方法时是阻塞的,它会一直等到数据到来时(或超时)才会返回:同样,在调用ServerSocket.accept() ...
 - HDU 2222 & ac自动机模板
			
题意: 求n个模板串在匹配串中出现了几个. SOL: 反正就是模板啦...似乎比KMP都简单----这么说似乎有点不道德...毕竟先看的KMP而他们并没有什么不同... 貌似自己的理解和他们画的图还是 ...
 - over
			
overflow内容溢出要用到: scroll(内容溢出,出现滚动条) auto(自动适应) hidden(超出隐藏) overflow-y:scroll: 沿着y轴出现滚动条: overflow-x ...