一、maven的作用
Java的基础开发阶段,主要是用maven来自动导入jar包,maven的核心思想是:约定大约配置
二、maven下载:
下载地址:http://maven.apache.org/download.cgi
三、配置maven的环境变量
-
在系统的环境变量下配置
M2_HOME F:\apache-maven-3.6.3\bin MAVEN_HOME F:\apache-maven-3.6.3 path %MAVEN_HOME%bin 在控制台测试maven是否配置成功
在控制台测试maven是否配置成功:输入mvn -version
四、maven中setting设置
镜像文件:下载的地址
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*,!jeecg,!jeecg-snapshots</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
本地仓库:localRepository
<localRepository>F:\apache-maven-3.6.3\maven-repo</localRepository>
五、在idea中实现maven
六、设置idea中的maven
-
2、设计web目录:为目录做标记
七、介绍maven中的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--maven版本和头文件-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!--这里就是我们配置的 GAV-->
<groupId>com.xiaoming</groupId>
<artifactId>java_04_maven</artifactId>
<version>1.0-SNAPSHOT</version>
<!--package:项目的打包方式
jar:java应用
war:javaweb应用-->
<packaging>war</packaging>
<name>java_04_maven Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<!--项目的默认构建编码-->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!--编码版本-->
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<!--项目依赖-->
<dependencies>
<!--具体的项目依赖包-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>java_04_maven</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
八、maven中文件资源导出问题
在pom.xml中配置:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
九、遇到的问题
unable to import maven :jdk和maven不兼容——换一个版本的maven
tomcat闪退 starup.bat中加一个pause
maven中的web.xml和tomcat一样保持一致