下载maven安装包
点击下载后,讲压缩包解压到一个自己熟悉固定的位置。
maven环境变量的配置
添加M2_HOME:对应Maven的解压目录即可。这里的目录到bin目录的上一级。
编辑Path环境变量:
测试,在cmd窗口输入mvn -v查看,出现如下结果则配置成功。
修改配置文件
通常我们需要修改的文件是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>
-->
<localRepository>D:\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>
-->
添加国内镜像源
由于maven中央仓库在国外,因此下载速度很慢,换源后下载速度更快
<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>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
</mirrors>
还有可以使用的国内仓库。
<!-- 中央仓库1 -->
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo1.maven.org/maven2/</url>
</mirror>
<!-- 中央仓库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默认的JDK版本
在标签下添加一个标签,修改maven默认的JDK版本。
<profile>
<id>JDK-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
idea下的maven配置
-DarchetypeCatalog=internal
这样windows下的maven就完全配好了。
最后补充一下Delegate IDE build/run action for maven 这个选项最好也要勾上不然可能会出现一些问题。
IDEA build委托到Maven build – 解决代码没有编译错误运行却报错: "程序包xxx不存在"的问题