34

The top of my web.xml file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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_5.xsd"
    version="2.5">

But I still get the warning from Eclipse (Ganymede) that no XML schema is detected, and schema violations are not being warned about. Other XML files in my project (Spring Framework configuration files for example) don't have the warning and do give correct warnings about schema violations.

How do I get the schema checking working and hopefully the warning to go away? The server does run correctly. It just appears to be an IDE issue.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Brian Deacon
  • 21,384
  • 13
  • 39
  • 41
  • you can also see my answer [for similar question on](https://stackoverflow.com/questions/4551783/no-grammar-constraints-dtd-or-xml-schema-detected-for-the-document). Basically, just write your xml to conform to required rule – Damilola Aug 15 '14 at 11:32

6 Answers6

47

I hate that warning too. Specially because it appears in XML files that you haven't written but appear in your project for whatever reason (if you use MAVEN it's hell).

With Eclipse 3.5+ you can easily remove this validation rule. Go to Preferences-->XML-->XML FILES --> Validation and Select "ignore".

You may also have to do a Project -> Clean for the validation warnings to go away.

alt text

Community
  • 1
  • 1
monzonj
  • 3,659
  • 2
  • 32
  • 27
  • I use Maven extensively and do not get this error on Maven files unless they are located in the target directory. In that case it is better to add a rule to disable validation in the target directory than it is to ignore the error. – Dave Feb 23 '12 at 04:43
  • 6
    This doesn't fix the problem, just hide the symptom. – Thorbjørn Ravn Andersen Jan 29 '13 at 10:41
  • 3
    I would NOT do this **Preferences | XML | XML Files | Validation** in Eclipse as this only mask/hide the error, it does not _solve_ the error. If you only use Eclipse to build Android applications, then this "solution" is acceptable. But if you use Eclipse to build other Java projects - JSF, etc - it will break these projects if XML validation is "turned off". So be careful. The real solution is for Oracle, Google and IBM to update their softwares with updated DTDs and schemas. – ChuongPham Jan 18 '14 at 18:20
  • 1
    We have to deal with badly formed 3rd party files all the time, especially xml files, Yes it would be nice if they fixed them, but they don't, so I just need to switch off pointless warnings, so that I can see the important , real warnings. This fix really helped me, Thanks. – Chris Mills Mar 31 '17 at 14:19
27

Perhaps try:

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd

Instead of:

http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd

Also, the <!DOCTYPE ...> is missing:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<web-app
  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/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  version="2.5">
  <!-- ... -->
</web-app>
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
toolkit
  • 49,809
  • 17
  • 109
  • 135
10

Clear the cache for stored validation files.

Window > Preferences > General > Network Connections > Cache then remove all. Now go validate the file and see if that clears things up.

This happed to me and clearing the cache for the validation was the only way to get it functioning properly again. The advice for clearing dirty cache was found here.

Tiris
  • 160
  • 1
  • 12
  • This worked for me. Looks like at some point my Eclipse cached a bogus copy of http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd which was causing all my web.xml files to fail validation. – Brill Pappin Nov 03 '11 at 14:09
  • This worked for me too with when my Spring bean files started throwing this error. – Dave Feb 23 '12 at 04:41
2

If you have the same (missleading) error message because your XML Editor was not finding the XSD file, you can add a catalog entry.

You pick the URL specified for the schema, for a declaration like

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
                      http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"

The URL of the schema file (http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd) is specified for the namespace http://java.sun.com/xml/ns/j2ee. You can now redirect the location of the file with the workspace catalog in Eclipse:

Preferences -> XML -> XML Catalog -> Add..

Use

Key Type = Schema Location
Key = http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd

And then you can use the file chooser to pick actually a XSD file on the filesystem or the workspace.

eckes
  • 10,103
  • 1
  • 59
  • 71
0

The problem is two-fold:

  1. Eclipse ships with a cache of a lot of well-known XSD's. The name space and/or location you provide does not match any of these.
  2. So Eclipse tries to go looking for the XSD on the internet on the URI provided (may just work). Unfortunately it appears that after Oracle revised java.sun.com this mechanism just times out in Eclipse (apparently the server redirects to the homepage instead of simply saying "does not exist, sorry").

When you revise to the correct values for Java EE 5, the entry in the cache will be found and Eclipse will be happy.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
-5

Add this <!DOCTYPE ...> to your xml file. Please put it under <?xml ...>:

<!DOCTYPE ??? PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

??? = Your root element, now if your sub-element name is using a html reserved word you might be catching some errors, all you have to do is change them to a non-reserved word.

For example:
If your current sub-element is <img>, change it to <pic>...

sth
  • 222,467
  • 53
  • 283
  • 367