Bogus Eclipse warning for web.xml: "No grammar constraints (DTD or XML schema) detected for the document."
Solution 1
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>
Solution 2
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.
Solution 3
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.
Solution 4
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.
Brian Deacon
Updated on March 21, 2020Comments
-
Brian Deacon about 4 years
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.