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

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

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


当前回答

我有同样的问题,我甚至试图删除项目,并再次添加它。诀窍是删除.settings目录。

其他回答

最好的和简单的步骤为我解决这个问题 1)属性->项目facet ->取消选中/取消标记动态Web模块->应用的复选框 2)现在更改到所需的版本Apply 3)选中“动态web模块”复选框。 ——现在你完成了——

右键单击项目→属性;在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 ->更新项目。

另一种方法是编辑项目facet配置文件本身

将这一行中的动态web模块版本更改为3.0 - <installed facet="jst. xml "。网络”version = " 2.5 " / >

然后:

右键单击项目(在project Explorer面板中)。 选择Maven»更新项目(或按Alt+F5)

您将在Eclipse项目的.settings目录中找到该文件。

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

如果悉尼的回答仍然没有帮助,那么试试下面的答案。 按照悉尼的答案,去属性>项目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>