cvc-elt.1:找不到元素“web-app”的声明
当我在 Eclipse 中创建新的动态 Web 项目时,自动创建的 web.xml
显示以下错误:
cvc-elt.1:找不到元素“web-app”的声明
和红色背景:
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
我想知道为什么会发生此错误以及如何消除此错误。 我在项目中使用了 Eclipse 3.1 版、Apache Tomcat 5.0 和 JDK 1.4。我对 Eclipse 还很陌生。
When I created new dynamic web project in Eclipse, automatically created web.xml
showed the following error:
cvc-elt.1: Cannot find the declaration of element 'web-app'
and a red background on this line:
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
I want to know why this error occur and how to get rid of this error.
I used Eclipse version 3.1, Apache Tomcat 5.0 and JDK 1.4 in my project. I'm pretty new to Eclipse.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
错误:cvc-elt.1.a:找不到元素“web-app”的声明
问题:
此错误与Eclipse IDE<的web.xml文件有关/strong> 动态 Web 项目
此错误的主要原因是 Java Enterprise Edition (JEE) 支持不同。
自2019 年 8 月 13 日 Java EE Servlet API 由 Jakarta EE Servlet API
维护
由于这些包名称已更改为:
javax.servlet.*;
--->至 --->jakarta.servlet.*;
javax.servlet.http.*;
--->至 --->jakarta.servlet.http.*;
您的 IDE 可能仍在填充旧的
doc 类型声明
< strong>让 xml 文件兼容javax
package解决方案:
如果您使用的是新版本Tomcat 或其他 Java 服务器应用程序,检查它们是否正在使用新的
jakarta
包或旧javax
包。Tomcat 10 已迁移到 Jakarta EE,因此如果您使用 Tomcat 10,则可以使用
jakarta下面提到的 doctype 声明
。旧版本的正确声明
javax
包新版本的正确声明
jakarta
包Things I am working with:
面向企业 Java 和 Web 开发人员的 Eclipse IDE
版本:2021-12 (4.22.0)
版本号:20211202-1639*
Apache Tomcat
版本10.0.7
Error: cvc-elt.1.a: Cannot find the declaration of element 'web-app'
Issue:
This error is related to the web.xml file of Eclipse IDE Dynamic Web Project
The main root cause of this error is different Java Enterprises Edition (JEE) support.
From August 13, 2019 Java EE Servlet API is maintained by Jakarta EE Servlet API
As these package names are changed from:
javax.servlet.*;
---> to --->jakarta.servlet.*;
javax.servlet.http.*;
---> to --->jakarta.servlet.http.*;
Your IDE might still populating the old
doc type declaration
for xml files to be compatible withjavax
packageSolution:
If you're using new version of Tomcat or other Java Server Application, check whether they're working with new
jakarta
package or oldjavax
package.Tomcat 10 is already migrated to Jakarta EE so if you're using Tomcat 10 you can use the
jakarta doctype declaration
mentioned below.Correct Declaration for Old Version
javax
packageCorrect Declaration for New Version
jakarta
packageThings I am working with:
Eclipse IDE for Enterprise Java and Web Developers
Version: 2021-12 (4.22.0)
Build id: 20211202-1639*
Apache Tomcat
Version 10.0.7
您需要将
DOCTYPE
元素添加到 XML 的开头:You need to add the
DOCTYPE
element to the start of the XML:我在 Eclipse 4.1、Apache Tomcat 7.x 和 JDK 1.6 上看到了这一点。它显然与缓存 XSD 文件有关。 有些人提供了 web.xml 的替代语法。使用 DTD 而不是模式的 XML。但我已经成功使用了一种解决方案建议仅关闭缓存。更好的选择(也在最后一个链接)是手动下载并安装 XSD。
更新:我决定尝试自己下载其中一个 XSD,并尝试手动将其安装到 Eclipse XML 目录中。很明显,Java XSD 服务器出现了问题——这显然是 Eclipse 在尝试下载和缓存 XSD 时看到的情况。也许当 Oracle/Sun 齐心协力并且服务器重新开始工作时,Eclipse 将停止给出此错误。与此同时,我必须关闭缓存并看看我能走多远。
更新:Sun 服务器恢复一段时间后,下载 XSD 文件并将其存储在本地的某个半永久位置。然后进入 Eclipse 首选项,搜索 XML 目录,并为其提供对 XSD 文件的引用。我已经验证这会阻止 Eclipse 尝试下载和缓存该文件。如果您不能信任 Sun 服务器,那么这是最好的解决方案——而且显然您不能。
I'm seeing this on Eclipse 4.1, Apache Tomcat 7.x, and JDK 1.6. It apparently has something to do with caching the XSD files. Some people provide an alternate syntax of web.xml that uses DTDs instead of schemas. But I've had success with one solution which suggested merely turning off caching. The better option, also at that last link, is to download and install the XSDs manually.
Update: I decided to try to download one of the XSDs myself and try to install it in the Eclipse XML catalog manually. It became obvious that the Java XSD server was having problems---which is apparently what Eclipse saw when it tried to download and cache the XSD. Perhaps when Oracle/Sun gets its act together and the server starts working again, then Eclipse will stop giving this error. In the meantime, I'll have to turn off caching and see how far I get.
Update: Once the Sun server comes back up for a little while, download the XSD file and store it in some semi-permanent place locally. Then go into the Eclipse preferences, search for the XML Catalog, and give it a reference to the XSD file. I've verified this prevents Eclipse from trying to download and cache the file. This is the best solution if you can't trust the Sun servers---and apparently you can't.
对我来说它现在正在工作
替换为这个 -
For me its working now
Replace with this -
<web-app version="3.0" 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">
我也遇到过这个问题,没有找到合理的地方。为了快速解决。完全删除您的工作区并再次克隆项目。您将不会再看到该问题。它帮助了我。
I also came across this problem and didn't found something reasonable. For quick solution. Delete your workspace entirely and take clone of project again. You won't see the problem again. It helped me.
当我无意中失去互联网连接时,我收到了此错误,这意味着 xsd 不可用。重新连接就解决了
I received this error when I unknowingly lost the internet connection meaning the xsd was not available. Reconnecting solved it
删除工作区并创建新工作区帮助我解决了此错误。我在 ZK Web 应用程序中收到此错误
Deleting the workspace and creating a new workspace has helped me to resolve this error. I was getting this error for the ZK web application
此问题与 Eclipse 自动生成的
web.xml
文件有关。在新版本的Java EE中,您必须将Java EE更改为Jakarta EE。
作为示例,将您的
开始标记更改为 [5/7/2022]:This issue is related to Eclipse auto-generated
web.xml
file.In new versions of Java EE, you must change Java EE to Jakarta EE.
As a sample change your
<web-app>
opening tag as this [5/7/2022]: