Java, JEE, Spring, JSF, Struts, Maven

Monday, September 8, 2008

Eclipse XML Catalog entry for DTD or XSD contained in jar

This is useful to fix the code-assist feature, when (for example, Facelets) the URI for a schema you are dealing with does not exist at its given location.

When defining a facelets taglib.xml, the DOCTYPE will be:


<!DOCTYPE facelet-taglib PUBLIC
"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"http://java.sun.com/dtd/facelet-taglib_1_0.dtd">


However, "http://java.sun.com/dtd/facelet-taglib_1_0.dtd" returns a 404. As a result, code-assist is not available when editing the file. The DTD in question is packaged in the facelets jar. It is possible to tell eclipse to get the DTD from the jar instead of the actual web resource.


  • Go to Window...Preferences.

  • Expand "Web and XML" and select XML Catalog (the actual names here may vary depending on version of Eclipse).

  • Select "User Specified Entries" and click "Add...".

  • Provide the following


    Location:
    "jar:file:T:/Edc/incubator/m2-repository/com/sun/facelets/jsf-facelets/1.1.14/jsf-facelets-1.1.14.jar!/facelet-taglib_1_0.dtd"
    Key Type:
    "Public ID"
    Key:
    "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"



Note in my case I'm pointing to a jar in a maven repository, but you can also point to a jar in your workspace.