Maven创建Webapp项目时,如何设置JDK版本以及servlet版本!

时间:2022-06-11 11:40:11

maven默认创建的项目,每次执行maven更新的时候总会将jdk版本设置成1.5

如果要固定JDK版本,需要在pom文件中添加以下代码



...
<dependencies>
...
</dependencies>
<build>
...
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>


修改servlet版本需要在工程目录下查找 ./setting/org.eclipse.wst.common.project.facet.core.xml文件 修改对应的jst.web部分的version内容设置为3.1,代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="jst.web" version="3.1"/>
<installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="java" version="1.8"/>
</faceted-project>


由于2.x与3.x的web.xml文件格式不同所以继续修改工程里面的web.xml

<?xml version="1.0" encoding="UTF-8"?>  
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>Archetype Created Web Application</display-name>
</web-app>