Bogus Eclipse warning for web.xml: “No grammar constraints (DTD or XML schema) detected for the document.”

前端 未结 6 961
忘了有多久
忘了有多久 2020-12-29 02:47

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




        
相关标签:
6条回答
  • 2020-12-29 02:54

    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

    0 讨论(0)
  • 2020-12-29 02:55

    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.

    0 讨论(0)
  • 2020-12-29 02:56

    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>...

    0 讨论(0)
  • 2020-12-29 02:57

    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.

    0 讨论(0)
  • 2020-12-29 03:03

    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.

    0 讨论(0)
  • 2020-12-29 03:04

    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>
    
    0 讨论(0)
提交回复
热议问题