1、创建一个空项目
2、idea的版本不同出现的界面有区别,这里直接弹出了创建模块的界面,选择创建一个模块
3、这里选择创建一个web模块
这里可以根据需要进行调整,Maven home directory选择你本地maven的文件位置,User settings file选择maven配置文件,也可以默认不选择,Local repostitory本地jar文件仓库位置,可以使用默认位置
这里红色区域还可以进行设置,后面需要再演示
这里可以选择自动导入 Enable Auto-Import
也可以到设置里面设置自动导入 ,勾选Import Maven projects automaically
上面创建项目时报错:Unable to import maven project,是因为maven版本不匹配,可以尝试降低版本,我这里将maven3.6改为maven3.3
4、porm.xml介绍
pom文件可以被子模块继承
<groupId>com.lisheng.project</groupId>
<artifactId>maven-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<spring.version>5.0.5.RELEASE</spring.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId></groupId>
<artifactId></artifactId>
</dependency>
</dependencies>
1)packaging标签是指打包的方式,默认是jar
2)groupId组ID
3)artifactId项目名
4)version版本号
5)dependencyManagement 加强管理依赖,父工程加入这个标签后,子模块不能自动继承父依赖,需要子模块添加dependencies标签声明后才能继承
6)properties标签用来在父工程中管理依赖版本
7)build管理插件,这里示例(maven-compiler-plugin)是一个编译版本的插件,一般建议编译版本和jdk相同,否则在编译时可能会出问题
或者一个可以在这里进行修改编译版本
8)如果是一个父项目,必须遵循两点
1、packaging标签的文本内容必须设置为pom
2、把src目录删除
5、创建一个父工程
6、在父项目下创建一个子模块
这里有继承关系,所以和上面建立web项目时有一点区别,GroupId,parent以及Version不能改变
7、这里有继承关系
parent标签标识父项目位置
modelVersion 父项目版本