[TOC]
下载地址:https://maven.apache.org/download.html
-
bin
mvn在bin目录中,主要用来构建项目
-
boot
maven自身运行所需要的类加载器
-
conf
settings.xml是maven的主要配置文件
-
lib
maven自身运行所需要的jar包
- 添加环境变量MAVEN_HOME,变量值为maven目录路径
- 添加环境变量PATH,变量值为maven下bin目录
- 检测环境变量配置是否成功,cmd运行mvn -v查看maven版本信息
修改conf/settings.xml文件修改相关设置
-
修改本地仓库位置
添加
localRepository
节点,设置本地仓库位置<localRepository>D:/maven/repository</localRepository>
-
修改中央仓库位置
阿里云中央仓库镜像:https://maven.aliyun.com/mvn/view
在
mirrors
结点中添加mirror
节点,设置相关信息<mirrors> <mirror> <id>aliyunmaven</id> <mirrorOf>*</mirrorOf> <name>阿里云公共仓库</name> <url>https://maven.aliyun.com/repository/public</url> </mirror> </mirrors>
- src
- main
- java ——核心代码部分
- resources ——配置文件部分
- test
- java ——测试代码部分
- resources ——测试配置文件
- webapp(web工程存在该目录,保存页面资源文件,js/css/html等)
- main
- mvn clean——清除之前构建的项目
- mvn compile——编译当前项目
- mvn test——编译核心代码及测试代码
- mvn package——项目编译及打包,打包格式受pom中标签控制,默认为jar包
- mvn install——项目编译并打包,并将该包安装到本地仓库
- mvn deploy——项目发布
设置为本地maven
一般情况下创建Maven项目是需要联网的,设置此参数后会直接从本地需要相应插件而不从网络下载,防止在网络不良的情况下不能创建项目
参数:-DarchetypeCatalog=internal
在pom.xml中添加相关结点,修改环境配置
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>8080</port>
</configuration>
</plugin>
</plugins>
</build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<target>1.8</target>
<source>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
与在工程中指定版本功能相同,在 Maven 的conf/settings.conf中添加如下节点以配置JDK
<profiles>
<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>
</profiles>