原文地址: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

点击http://search.maven.org

就会找到中央仓库的搜索内容的来源

log4j、hibernate等都可以在这搜索到。

例如,我搜索hibernate

我选择一个点击

然后选一个版本,就可以看到

然后只要利用页面左侧的依赖描述复制下来,就可以使用了。

<dependency>
<groupId>hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.4.0.GA</version>
</dependency>

Maven入门系列(二)--设置中央仓库的方法的更多相关文章

  1. idea上使用maven入门(二)——本地仓库以及使用maven

    本地仓库: 首先创建完一个项目之后,点击左上角file->setting(建一个文件夹repository,建议创建到maven的外面,主要如果maven需要换版本,方便管理)如下图: ​ ma ...

  2. Maven学习系列二(1-5)

    Maven学习系列二(1-5) 本文转自 QuantSeven 博客,讲解精炼易懂,适合入门,链接及截图如下 http://www.cnblogs.com/quanyongan/category/47 ...

  3. 清晰的教你如何将 Maven 项目上传至 中央仓库以及版本更新

    项目中总会依赖一些大牛的开源库,例如 Android 开发 通过以下方式就可以方便的引入库.那么如何将我们自己的库也能这样来使用呢?下面我们将详细的讲解每一步的过程: implementation ' ...

  4. C# 互操作性入门系列(二):使用平台调用调用Win32 函数

    好文章搬用工模式启动ing ..... { 文章中已经包含了原文链接 就不再次粘贴了 言明 改文章是一个系列,但只收录了2篇,原因是 够用了 } --------------------------- ...

  5. [转]C# 互操作性入门系列(二):使用平台调用调用Win32 函数

    传送门 C#互操作系列文章: C# 互操作性入门系列(一):C#中互操作性介绍 C# 互操作性入门系列(二):使用平台调用调用Win32 函数 C# 互操作性入门系列(三):平台调用中的数据封送处理 ...

  6. mybatis入门系列二之输入与输出参数

    mybatis入门系列二之详解输入与输出参数   基础知识   mybatis规定mapp.xml中每一个SQL语句形式上只能有一个@parameterType和一个@resultType 1. 返回 ...

  7. C语言高速入门系列(二)

    C语言高速入门系列(二) -----转载请注明出处coder-pig 本节引言: 在前面一节中我们对C语言进行了初步的了解,学会了使用IDE进行代码的编写,编译执行! 在这一节中我们会对C语言的基本的 ...

  8. Java-Maven(八):IDEA使用本地maven,并配置远程中央仓库

    声明:已经安装了maven,安装请参考:<Java-Maven(一):Maven的简介与安装> 1)一般我们从github.码云(https://gitee.com)上获取代码后,实际上我 ...

  9. Maven入门(二)pom.xml和核心概念

    一.pom.xml文件说明 1.pom意思就是project object model. 2.pom.xml包含了项目构建的信息,包括项目的信息.项目的依赖等. 3.pom.xml文件是可以继承的,大 ...

随机推荐

  1. POJ 2503 字典树

    题目链接:http://poj.org/problem?id=2503 题意:给定一个词典,输入格式为[string1' 'string2]  意思是string2的值为string1. 然后给定一波 ...

  2. 现代JavaScript

    1.async(异步)属性以及defer(延迟)属性 2.load事件是在所有资源被完全加载后才触发 3.domready,在DOM加载之后以及资源加载之前被触发,以DOMContentLoaded的 ...

  3. 【Clr in c#】泛型

    使用泛型的好处是“代码重用”,极大的提高了开发效率,泛型为开发者提供了以下优势: 1,源代码保护  算法的源代码不需要提供给使用泛型算法的开发人员,使用c++模板的泛型技术需要提供.(目前c++模板的 ...

  4. 简单的实现UIpicker上面的取消确定按钮

    1 因为我用的xib实现的添加picker 和textfiled的, @interface ViewController : UIViewController<UITextFieldDelega ...

  5. memcache/redis 缓存学习笔记

    0.redis和memcache的区别 a.redis可以存储除了string之外的对象,如list,hash等 b.服务器宕机以后,redis会把内存的数据持久化到磁盘上,而memcache则不会 ...

  6. WPF画线问题,几千条以后就有明显的延迟了。

      我现在是这么画的,class A { private GeometryGroup _lines; private Path _path; public A() {    _path.Data = ...

  7. ACM: 限时训练题解-Heavy Coins-枚举子集-暴力枚举

    Heavy Coins   Bahosain has a lot of coins in his pocket. These coins are really heavy, so he always ...

  8. CDOJ 1431 不是图论 Label:Tarjan || Kosarajn

    Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Description 给出一个nn个点, ...

  9. [WP8.1UI控件编程]SemanticZoom控件实现分组列表

    11.1.5 SemanticZoom实现分组列表 SemanticZoom控件可以让用户实现一种更加高级的列表,这种列表可以对列表的项目进行分组,同时这个SemanticZoom控件会提供两个具有相 ...

  10. Vijos1425子串清除 题解

    Vijos1425子串清除 题解   描述: 我们定义字符串A是字符串B的子串当且仅当我们能在B串中找到A串.现在给你一个字符串A,和另外一个字符串B,要你每次从B串中从左至右找第一个A串,并从B串中 ...