目录
目录创建Web项目
新建Maven Project
选择创建一个simple project
填写Group Id和Artifact Id然后选择Packaging 为war然后Finsh
增加Web项目需要的文件
此时项目创建成功但是报错,原因主要是缺少Web项目需要的文件
接下来需要将缺少的文件补全,右键项目选择Properties,然后选择Project Facets
然后先取消选择Dynamic Web Module点Apply,接着再选择此项会出现如下界面
点击黄色条目,然后将Content directory修改为src/main/webapp
此时Web项目需要的文件就有了
修改Jdk版本
但此时的Jdk版本是1.5需要我们将其改为1.8。
方式一(一劳永逸):
在Maven根目录的conf下的settings.xml文件中找到profiles标签,并在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>
方式二(需每次配置):
在项目的pom.xml文件下加入如下代码:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
在其上任何方式配置完后对项目进行更新:
增加Servlet依赖
此时新建jsp页面会有错误提示,那是因为没有Servlet的依赖,加入如下依赖后错误消失。
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
网友评论