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

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

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


当前回答

我的Web模块3.0在Web .xml,但在属性>动态Web模块它是3.1

我把web.xml修改成这样:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">

在此更改后,做:右键单击项目>Maven>更新项目…

其他回答

右键单击项目→属性;在Project Facets中,取消选择Dynamic Web Module(版本应为3.1)和JavaServer Faces(版本应为2.2)。

改变:

<web-app version="3.1" 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">

:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:javaee="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

然后删除param-name等前面的前缀。

最后,Maven ->更新项目。

我更新了我的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 ->更新项目…

对于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哪个版本是一个很好的说明。

如果悉尼的回答仍然没有帮助,那么试试下面的答案。 按照悉尼的答案,去属性>项目facet取消选择动态Web模块,然后改变版本以匹配您的网页。配置,然后再次选择。应用>保存 然后是Maven更新。

web . xml

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:web="http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="Web_App_1" version="3.1">

<display-name>JavaServerFaces</display-name>

<!-- Change to "Production" when you are ready to deploy -->
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>

<!-- Welcome page -->
<welcome-file-list>
    <welcome-file>jsfs/hello.xhtml</welcome-file>
</welcome-file-list>

<!-- JSF mapping -->
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<!-- Map these files with JSF -->
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>jsfs/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

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