新建maven项目后,jre版本默认为1.5,web.xml版本默认为2.3。
点击项目名,右键选择Properties(最后一个),选择Project Facets,会看到版本号。默认应该为2.3和1.5
一、修改jdk版本,这个相对好修改。
两种方法。一种是改当前项目,另一种是改maven,以后新建maven项目都会自动使用设定的版本。
1、修改当前项目,pom.xml的project节点里面添加以下代码
<build>
<plugins>
<!-- compiler插件, 设定JDK版本 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
</plugins>
</build>
2、修改maven,conf下的settings.xml文件,在profiles节点里面添加以下代码
<profile>
<id>jdk-1.7</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.7</jdk>
</activation>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
</properties>
</profile>
参考的文章:
http://www.cnblogs.com/ystq/p/6340992.html
http://blog.csdn.net/peng_hong_fu/article/details/53584104
http://blog.csdn.net/kqygww/article/details/12922135
二、修改web.xml版本,有点麻烦,感觉改起来显得不够专业但是也没找到好的方法。
选择window-Show View-Navigator,左侧会出现Navigator标签,选择它,找到项目,.settings,打开org.eclipse.wst.common.project.facet.core.xml
将 <installed facet="jst.web" version="3.0"/> 中的2.3改为3.0。
还要修改web.xml文件的文件头,不同版本是不一样的。
3.1
<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">
</web-app>
3.0
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
</web-app>
2.5
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
</web-app>
2.4
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Servlet 2.4 Web Application</display-name>
</web-app>
2.3
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Servlet 2.3 Web Application</display-name>
</web-app>
参考的文章:
http://blog.csdn.net/ceclar123/article/details/38173755
http://www.mkyong.com/web-development/the-web-xml-deployment-descriptor-examples/