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

来源:互联网 发布:阿里云服务器二级域名 编辑:程序博客网 时间:2024/06/05 18:11

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

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



[html] view plain copy
  1. ...  
  2.   <dependencies>  
  3.        ...  
  4.   </dependencies>  
  5.   <build>  
  6.     ...  
  7.     <plugins>  
  8.         ...  
  9.         <plugin>  
  10.             <groupId>org.apache.maven.plugins</groupId>  
  11.             <artifactId>maven-compiler-plugin</artifactId>  
  12.             <version>3.1</version>  
  13.             <configuration>  
  14.                 <source>1.8</source>  
  15.                 <target>1.8</target>  
  16.             </configuration>  
  17.         </plugin>  
  18.     </plugins>  
  19.   </build>  
  20. </project>  


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

[html] view plain copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <faceted-project>  
  3.   <fixed facet="wst.jsdt.web"/>  
  4.   <installed facet="jst.web" version="3.1"/>  
  5.   <installed facet="wst.jsdt.web" version="1.0"/>  
  6.   <installed facet="java" version="1.8"/>  
  7. </faceted-project>  


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

[html] view plain copy
  1. <?xml version="1.0" encoding="UTF-8"?>    
  2. <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"    
  3.          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
  4.          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee    
  5.                              http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"    
  6.          version="3.1">    
  7.   <display-name>Archetype Created Web Application</display-name>  
  8. </web-app>  
转自:http://blog.csdn.net/cnxlk/article/details/52817594
阅读全文
0 0
原创粉丝点击