[版权申明] 非商业目的注明出处可自由转载,转载请标明出处!!!
博文地址:https://blog.youkuaiyun.com/cdpxc/article/details/109672322
出自:cdpxc(优快云 ID)
目录
1、[FATAL] Non-parseable settings
2、 Could not create local repository at D:\repository,不能创建本地仓库
3、修改settting.xml文件时,忽略xml文件的正文和注释格式
一、下载并安装Maven
1、安装Maven之前需要安装JDK环境,JDK的安装和环境配置见上篇博文;
2、Maven下载链接:https://maven.apache.org/download.cgi
本博文的系统环境:Win 10 64 bit JDK-15.0.1
(1)选择进入Apache的Maven官网-Download-二进制压缩包apache-maven-3.6.3-bin.zip-解压到"apache-maven-3.6.3-bin"文件夹;

(2)-解压之后可以看到,打开apache-maven-3.6.3-bin文件夹内部有apache-maven-3.6.3,然后再打开发现就是bin等和JDK安装完成后包含的很相似的内容了。而且并没有可执行文件.exe,这就说明,免安装了,放入某个目录下,添加环境变量即可。

(3)将apache-maven-3.6.3文件夹的所有内容复制到C:Program files下(你复制到你想复制的位置即可),即算是在该目录下安装完成。
二、Maven环境配置
是不是相同的配方,熟悉的味道?
新建Maven主路径: 变量名称 MAVEN_HOME 变量位置: C:\Program Files\apache-maven-3.6.3

添加Maven路径之path: 在path中添加位置:

三、Maven环境配置
找到刚刚放置maven的位置,使用Notepad++打开子文件中conf内的settting.xml,我的为C:\Program Files\apache-maven-3.6.3\conf\settting.xml
(使用其他的软件打开xml文件也可以,我是习惯用notepad++,可以清晰看到代码行数,查找也很方便。)
注意:1)xml的注释为<!-- note -->格式,如下:
<!-- interactiveMode
| This will determine whether maven prompts you when it needs input. If set to false,
| maven will use a sensible default value, perhaps based on some other setting, for
| the parameter in question.
|
| Default: true
<interactiveMode>true</interactiveMode>
-->
2)xml的正文内容为<setname>---------</setname>格式,如下:
<server> <!-- 开头 -->
<id>deploymentRepo</id> <!-- 设置的内容 -->
<username>repouser</username>
<password>repopwd</password>
</server> <!-- 结尾 -->
因此,观察settting.xml文件可以看到,几乎全篇都是注释,因此,很多配置是需要自己去根据注释添加的。(这也是我用notepad++观察发现的)

3)为了出错方便恢复原样,建议a)复制settting.xml,或者 b)保留xml文件内的所有注释,不取消注释修改,而是新添加代码行
4)最后附上我的settting.xml
1、本地仓库配置
找到<!-- localRepository,如果不修改默认的位置为/path/to/local/repo,即~/.m2/repository,~表示当前系统登陆用户,即User/username/.m2/repository
修改这个地方的目的:为了将仓库转移到其他盘中,释放C盘的空间,像我这样只有一个盘的其实没有必要修改。但为了自己方便找到,我也创建在了很容易找的位置C:\repository
<localRepository>/path/to/local/repo</localRepository></localRepository> <!-- 模板 -->
<localRepository>C:\repository</localRepository> <!-- 修改为自己想存储的仓库的文件位置 -->
我添加的方式如下,保证C:\repository的位置在<localRepository>和</localRepository>之间

2、镜像配置
部分参考了Maven配置阿里云仓库 和 maven仓库中心mirrors配置多个下载中心(执行最快的镜像)等博主的内容。
只要添加一个最快地镜像即可,因为添加再多,也只会查找第一个镜像的位置,但都添加上也可以,方便修改。在国内,一般选择阿里云仓库。
<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>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
</mirrors>
使用Notepad++修改后保存会提示:保存失败,用管理员模式启动,点击“是”即可。
3、JAVA版本配置
上篇java配置的博文中已经说了我的电脑安装的是JDK 15版本的,因此,需要对java默认1.4的版本进行修改。
其实只需要将注释中的代码替换成自己的即可,如下:

四、验证Maven添加内容是否正确
同样Win+R或者搜索栏输入cmd,找到命令提示符
1、验证Maven环境变量添加是否正确
输入mvn -version 或者 mvn --version 或者 mvn -v (与JDK不同),均可,出现Maven主路径及JDK的相关信息,即正确,如下图。

2、验证本地仓库和镜像是否正确
在命令提示符中输入,mvn help:system,出现很长的关于阿里云镜像的信息,最终显示”BUILD SUCCESS“, 即配置成功。

五、Maven安装配置过程中可能出现的错误
大家看到英文错误提示一定不要慌,曾经我也很害怕,觉得按照技术贴操作,不知道为什么出错,出了错也不知所措。现在很多人都会无私分享一些经验,可以参考。但有时候经验不是都会被分享,因此,总是有些路需要自己一个人走的。
加油!(不明白为啥写这句鸡汤,可能是因为安装软件总会出错,曾经都荒谬的以为“软件克我”,其实是我心里太怯懦,害怕失败和问题,其实,慢慢会成长的,但如果一开始就不怕,成长或许会更快!)
1、[FATAL] Non-parseable settings
采用mvn help:system验证时,报错“[FATAL] Non-parseable settings ”,自习观察给出的错误提示,是安装在 C:\Program Files\apache-maven-3.6.3的文件夹中的子文件conf内的settting.xml报错,这不正是前面所说的配置修改的文件吗?
所以,肯定是有地方写的出错了,再看问题是““--“后面需要接的字符是”>“符号”而不应该是....(看不懂了)。后面又给出了错误语句的样子“ <!---- ... @154:10)”,后面又出现了第153行第10列。那么估计这句火星文“ <!---- ... @154:10)”是出错的问题和位置了。
使用Notepad++软件打开settting.xml找到第153行,果然存在相同的内容。那估计是需要2个-,而不是4个-,修改后,保存,继续进行mvn help:system验证,不再报相同的错误,说明此错误修改正确。

2、 Could not create local repository at D:\repository,不能创建本地仓库
第一个问题解决以后,又继续报错,错误提示是不能创建本地仓库,我查了一些文章,说没有权限什么的,需要给仓库设置权限,我尝试查找如果修改文件权限,但忽然又想好多人这样没问题,为啥我的有问题?
又看了一遍错误提示。忽然想到我的系统只有C盘,没有D盘这个东东,怪不得报错,谁弄也会报错啊。于是,又回去修改settting.xml,找到创建本地仓库的位置,修改为 C:\repostory,保存,继续进行mvn help:system验证,不再报相同的错误。

3、修改settting.xml文件时,忽略xml文件的正文和注释格式
注意,修改settting.xml文件时,一定要注意xml文件的正文和注释格式。有可能你不懂xml文件正文是什么,注释怎么弄,但要注意观察这个文件中的内容。
六、附件settting.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.
-->
<!--
| This is the configuration file for Maven. It can be specified at two levels:
|
| 1. User Level. This settings.xml file provides configuration for a single user,
| and is normally provided in ${user.home}/.m2/settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -s /path/to/user/settings.xml
|
| 2. Global Level. This settings.xml file provides configuration for all Maven
| users on a machine (assuming they're all using the same Maven
| installation). It's normally provided in
| ${maven.conf}/settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -gs /path/to/global/settings.xml
|
| The sections in this sample file are intended to give you a running start at
| getting the most out of your Maven installation. Where appropriate, the default
| values (values used when the setting is not specified) are provided.
|
|-->
<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">
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository></localRepository>
-->
<localRepository>C:\repository</localRepository>
<!-- interactiveMode
| This will determine whether maven prompts you when it needs input. If set to false,
| maven will use a sensible default value, perhaps based on some other setting, for
| the parameter in question.
|
| Default: true
<interactiveMode>true</interactiveMode>
-->
<!-- offline
| Determines whether maven should attempt to connect to the network when executing a build.
| This will have an effect on artifact downloads, artifact deployment, and others.
|
| Default: false
<offline>false</offline>
-->
<!-- pluginGroups
| This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
| when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
| "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
|-->
<pluginGroups>
<!-- pluginGroup
| Specifies a further group identifier to use for plugin lookup.
<pluginGroup>com.your.plugins</pluginGroup>
-->
</pluginGroups>
<!-- proxies
| This is a list of proxies which can be used on this machine to connect to the network.
| Unless otherwise specified (by system property or command-line switch), the first proxy
| specification in this list marked as active will be used.
|-->
<proxies>
<!-- proxy
| Specification for one proxy, to be used in connecting to the network.
|
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
-->
</proxies>
<!-- servers
| This is a list of authentication profiles, keyed by the server-id used within the system.
| Authentication profiles can be used whenever maven must make a connection to a remote server.
|-->
<servers>
<!-- server
| Specifies the authentication information to use when connecting to a particular server, identified by
| a unique name within the system (referred to by the 'id' attribute below).
|
| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
| used together.
|
<server>
<id>deploymentRepo</id>
<username>repouser</username>
<password>repopwd</password>
</server>
-->
<!-- Another sample, using keys to authenticate.
<server>
<id>siteServer</id>
<privateKey>/path/to/private/key</privateKey>
<passphrase>optional; leave empty if not used.</passphrase>
</server>
-->
</servers>
<!-- mirrors
| This is a list of mirrors to be used in downloading artifacts from remote repositories.
|
| It works like this: a POM may declare a repository to use in resolving certain artifacts.
| However, this repository may have problems with heavy traffic at times, so people have mirrored
| it to several places.
|
| That repository definition will have a unique id, so we can create a mirror reference for that
| repository, to be used as an alternate download site. The mirror site will be the preferred
| server for that repository.
|-->
<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>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
<!-- maven运营的中央仓库2 -->
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>
<!-- maven在UK架设的仓库(有时候速度会比官方2号仓库快) -->
<mirror>
<id>ui</id>
<name>Mirror from UK</name>
<url>http://uk.maven.org/maven2/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<!-- JBoss的仓库 -->
<mirror>
<id>jboss-public-repository-group</id>
<mirrorOf>central</mirrorOf>
<name>JBoss Public Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>ibiblio</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
</mirror>
<!-- maven运营的中央仓库1 -->
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo1.maven.org/maven2/</url>
</mirror>
<mirror>
<id>CN</id>
<name>OSChina Central</name>
<url>http://maven.oschina.net/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>net-cn</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://maven.net.cn/content/groups/public/</url>
</mirror>
<mirror>
<id>JBossJBPM</id>
<mirrorOf>central</mirrorOf>
<name>JBossJBPM Repository</name>
<url>https://repository.jboss.org/nexus/content/repositories/releases/</url>
</mirror>
</mirrors>
<!-- profiles
| This is a list of profiles which can be activated in a variety of ways, and which can modify
| the build process. Profiles provided in the settings.xml are intended to provide local machine-
| specific paths and repository locations which allow the build to work in the local environment.
|
| For example, if you have an integration testing plugin - like cactus - that needs to know where
| your Tomcat instance is installed, you can provide a variable here such that the variable is
| dereferenced during the build process to configure the cactus plugin.
|
| As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
| section of this document (settings.xml) - will be discussed later. Another way essentially
| relies on the detection of a system property, either matching a particular value for the property,
| or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
| value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
| Finally, the list of active profiles can be specified directly from the command line.
|
| NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
| repositories, plugin repositories, and free-form properties to be used as configuration
| variables for plugins in the POM.
|
|-->
<profiles>
<!-- profile
| Specifies a set of introductions to the build process, to be activated using one or more of the
| mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
| or the command line, profiles have to have an ID that is unique.
|
| An encouraged best practice for profile identification is to use a consistent naming convention
| for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
| This will make it more intuitive to understand what the set of introduced profiles is attempting
| to accomplish, particularly when you only have a list of profile id's for debug.
|
| This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
<profile>
<id>jdk-1.4</id>
<activation>
<jdk>1.4</jdk>
</activation>
<repositories>
<repository>
<id>jdk14</id>
<name>Repository for JDK 1.4 builds</name>
<url>http://www.myhost.com/maven/jdk14</url>
<layout>default</layout>
<snapshotPolicy>always</snapshotPolicy>
</repository>
</repositories>
</profile>
-->
<profile>
<id>jdk-15</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>15</jdk>
</activation>
<properties>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
<maven.compiler.compilerVersion>15</maven.compiler.compilerVersion>
</properties>
</profile>
<!--
| Here is another profile, activated by the system property 'target-env' with a value of 'dev',
| which provides a specific path to the Tomcat instance. To use this, your plugin configuration
| might hypothetically look like:
|
| ...
| <plugin>
| <groupId>org.myco.myplugins</groupId>
| <artifactId>myplugin</artifactId>
|
| <configuration>
| <tomcatLocation>${tomcatPath}</tomcatLocation>
| </configuration>
| </plugin>
| ...
|
| NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
| anything, you could just leave off the <value/> inside the activation-property.
|
<profile>
<id>env-dev</id>
<activation>
<property>
<name>target-env</name>
<value>dev</value>
</property>
</activation>
<properties>
<tomcatPath>/path/to/tomcat/instance</tomcatPath>
</properties>
</profile>
-->
</profiles>
<!-- activeProfiles
| List of profiles that are active for all builds.
|
<activeProfiles>
<activeProfile>alwaysActiveProfile</activeProfile>
<activeProfile>anotherAlwaysActiveProfile</activeProfile>
</activeProfiles>
-->
</settings>

本文详细介绍了如何在Windows 10环境下安装和配置Maven 3.6.3,包括下载安装、环境变量设置、本地仓库转移至C:
epository、配置阿里云镜像加速以及解决[FATAL] Non-parseable settings等常见错误。


2万+





