您的位置:首页 > 移动开发 > WebAPP

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

2017-10-26 17:02 549 查看
maven默认创建的项目,每次执行maven更新的时候总会将jdk版本设置成1.5

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

[html] view
plain copy

...  

  <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,代码如下:

[html] view
plain copy

<?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

[html] view
plain copy

<?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>  

转自:http://blog.csdn.net/cnxlk/article/details/52817594
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  maven web