Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cvc-elt.1: Cannot find the declaration of element 'web-app'

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.

like image 805
Phyo Wai Avatar asked Aug 16 '11 04:08

Phyo Wai


2 Answers

You need to add the DOCTYPE element to the start of the XML:

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
like image 74
sanjay Avatar answered Nov 19 '22 11:11

sanjay


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.

like image 3
Garret Wilson Avatar answered Nov 19 '22 10:11

Garret Wilson