Maven配置本地仓库

当我们在myeclipse中update maven时可能会报错User setting file does not exist C:Userslenevo.m2setting.xml,以致于更新不能成功。

经本人研究maven的官方说明,得到解决方案如下:将maven的安装目录conf目录下的setting.xml拷贝到C:Userslenevo.m2目录下即可。

通过研究发现还可以解决令一种问题:如果我们修改maven的安装目录conf目录下的setting.xml的repository的值,使得新的 jar不在 C:Userslenevo.m2中存在而在新的目录中存在,而事实上这却对maven执行时下载jar包的位置没有影响,这就是由于C: Userslenevo.m2setting.xml对maven的影响。由于C:Userslenevo.m2setting.xml 文件没有变化,只修改maven的安装目录conf目录下的setting.xml也无济于事。

附maven关于这方面的说明:(url:http://maven.apache.org/settings.html

The settings element in the settings.xml file contains elements used to define values which configure Maven execution in various ways, like the pom.xml, but should not be bundled to any specific project, or distributed to an audience. These include values such as the local repository location, alternate remote repository servers, and authentication information.

There are two locations where a settings.xml file may live:

  • The Maven install: $M2_HOME/conf/settings.xml
  • A user's install: ${user.home}/.m2/settings.xml

The former settings.xml are also called global settings, the latter settings.xml are referred to as user settings. If both files exists, their contents gets merged, with the user-specific settings.xml being dominant.

Tip: If you need to create user-specific settings from scratch, it's easiest to copy the global settings from your Maven installation to your ${user.home}/.m2 directory.

翻译如下:

settings.xml中的settings元素包括了用于定于值的元素,这些值配置了maven执行的多种方式,像pom.xml,但是不用哪个绑定到任何具体的项目,或者分配给一个用户。这些值包括local repository的位置,更改remoterepository 服务器,和认证的信息。
settings.xml可能存在于两个位置:
1:maven的安装路径$M2_HOME/conf/settings.xml
2: 用户安装 ${user.home}/.m2/settings.xml
前面一个settings.xml也被称为全局配置,后者settings.xml用作用户配置。如果两个文件都存在,它们的内容合并在一起,user-specific settings.xml成为主导的文件。

小贴士:如果你需要从scratch创建user-specific settings.xml,最简单的方法是从你的maven安装路径下贝全局配置到你的${user.home}/.m2目录下。

安装Maven后我们会在用户目录下发现.m2 文件夹。默认情况下,该文件夹下放置了Maven本地仓库.m2/repository。所有的Maven构件(artifact)都被存储到该仓库中, 以方便重用。但是windows用户的操作系统都安装在C盘,把Maven仓库放到C盘是很危险的,为此我们需要修改Maven的本地仓库路径。

      修改方式如下:

  • 手动创建本地仓库的存放路径,例如:D:Javam2 epository;
  • 在windows的环境变量中增加了新的用户变量M2_REPO,其对应的值为D:Javam2 epository(Maven仓库的本地存放路径),同时把这个变量增加到path变量中;
  • 修改Maven安装目录下的 conf/文件夹内的setting.xml文件,新增一行:<localRepository>D:Javam2 epository</localRepository>(表示本地仓库的地址为:D:Javam2 epository);
  • 将上一步修改好的setting.xml文件复制到D:Javam2 epository目录下一份;
  • 修改MyEclipse中Maven的配置信息。

         1.打开myeclipse点击windows->preferences->maven->installations下add一个 已经安装到D:Java目录下的maven,如:D:Javamaven-3.0.4,并勾选此新加项。并点击下面的browse按钮打开 maven的全局配置文件,如:D:Javamaven-3.0.4confsetting.xml。

         2.打开myeclipse点击windows->preferences->maven->User setting下修改user setting选项为:D:Javam2 epositorysettings.xml,并点击update settings。并点击下面的reindex按钮更新索引。
         3.点击配置窗口的apply按钮,突出配置窗口。

      最后打开CMD,执行mvn help:system会发现Maven从远程库下载的jar包都会放到新修改后的路径D:Javam2 epository中了。

1.安装完maven之后,maven配置了默认的中央仓库,需要通过互联网访问。
中央仓库的配置目录:
${maven_home}/lib/maven-model-builder-3.1.1.jarorgapachemavenmodelpom.xml

http://blog.segmentfault.com/kylin_mountain/1190000000453887

原文地址:https://www.cnblogs.com/sos-blue/p/3690749.html