我正在使用maven在Eclipse中创建一个动态web应用程序。我添加了一些文件夹,如src/test/java和src/test/resources。我还更改了Java Build Path中的库,以获得JavaSE-1.7。到这里都没问题。

当我试图改变项目Facet动态Web模块时,出了问题。在同一个地方,我将Java更改为1.7。它仍然告诉我,不能将项目facet动态Web模块的版本更改为3.0。

我已经改变了所有我认为会影响改变的东西。


当前回答

Click on your project folder. Go to Window > Show View > Navigator Go to Navigator and expand the .settings folder Open org.eclipse.wst.common.project.facet.core.xml file <?xml version="1.0" encoding="UTF-8"?> <faceted-project> <fixed facet="wst.jsdt.web"/> <installed facet="jst.web" version="2.3"/> <installed facet="wst.jsdt.web" version="1.0"/> <installed facet="java" version="1.8"/> </faceted-project> Change the version like this <installed facet="jst.web" version="3.1"/> Save Just update your project. Right Click on The Project Folder > Maven > Update Project > Select the Project and click 'Ok'

这招对我很管用。

其他回答

这个问题与版本右键单击项目->属性->项目Facets->右键单击动态Web模块->解锁它-> uncheck->选择2.5版本->应用->更新maven

Click on your project folder. Go to Window > Show View > Navigator Go to Navigator and expand the .settings folder Open org.eclipse.wst.common.project.facet.core.xml file <?xml version="1.0" encoding="UTF-8"?> <faceted-project> <fixed facet="wst.jsdt.web"/> <installed facet="jst.web" version="2.3"/> <installed facet="wst.jsdt.web" version="1.0"/> <installed facet="java" version="1.8"/> </faceted-project> Change the version like this <installed facet="jst.web" version="3.1"/> Save Just update your project. Right Click on The Project Folder > Maven > Update Project > Select the Project and click 'Ok'

这招对我很管用。

打开org.eclipse.wst.common.project.facet.core.xml文件并更改jst. core.xml文件。Web版本到3.0。还要将web.xml更新到3.0版本。保存并更新项目。希望这能有所帮助。我正在使用Eclipse Juno

对于maven eclipse web项目,更改动态web模块版本需要检查三个地方。如果你使用eclipse,并且在你检查了以下内容之后: 1) web . xml

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

2) maven:

<dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.0.1</version>
      <scope>provided</scope>   ## ensure you have tomcat 7 not other version
</dependency>

<plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.0</version>
      <configuration>
            <source>1.7</source> ## at least 6
            <target>1.7</target>
      </configuration>
</plugin>

3) eclipse构建路径和编译器版本为1.7

maven中仍然有一个错误标记:

cannot change version of project facet dynamic web module to 3.0 one or more constrants have not been satisfied

然后你可以: 取消选中动态web模块,并重新检查它。 我认为这是因为.settings的eclipse文件损坏了。关于第二个提示tomcat哪个版本是一个很好的说明。

我更新了我的web.xml

<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">
    <display-name>Servlet 3.0 Web Application</display-name>
</web-app>

然后只需Maven ->更新项目…