1.1 安装 Maven 核心程序
-
下载地址:http://maven.apache.org/
-
检查 JAVA_HOME 环境变量。Maven 是使用 Java 开发的,所以必须知道当前
系统环境中 JDK 的安装目录。 -
解压 Maven 的核心程序。
将 apache-maven-3.6.3-bin.zip 解压到一个非中文无空格的目录下。例如:D:apache-maven-3.6.3
-
配置环境变量。
MAVEN_HOME
D:apache-maven-3.6.3
path
%MAVEN_HOME%in
-
④查看 Maven 版本信息验证安装是否正确
mvn -v
配置本地仓库和阿里云镜像
Maven 默认的本地仓库:~.m2 epository 目录。
配置文件目录 D:apache-maven-3.6.3confsettings.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>
-->
配置案例云镜像
<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/groups/public</url>
</mirror>
</mirrors>
Eclipse配置Maven插件
Eclipse 中默认自带 Maven 插件,但是自带的 Maven 插件不能修改本地仓库
- 点击 Eclipse 中的 Window→Preferences
Eclipse创建Maven工程
配置右键新建菜单中有maven project
每次创建工程时版本都是1.5,如何修改
settings.xml 文件中添加以下配置将编译版本改为 1.8,重启 Eclipse 即可
<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>
在pom.xml文件中添加坐标 并保存测试
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
idea 创建maven工程
idea也有自带的maven插件,且有配置文件可以进行配置,在安装目录中的plubins中
转web工程使用该插件可以一键转