IBM Support

How to reference a DTD file that is contained in a JAR

Troubleshooting


Problem

A JAR file, log4j.jar, in []/WEB-INF/lib[] folder contains the DTD file, log4j.dtd. The log4j.dtd file is referenced in an XML file, log4j.xml, created to define the logger configuration as doctype: [] [] However, the XML validator could not find the log4j.dtd contained in the log4j.jar file. This technote describes several possible ways to reference a DTD file that is contained in a JAR file so that the validator can find the DTD file.

Resolving The Problem

There are several possible ways you could reference a DTD in a JAR so that the XML validator finds the DTD, but the method you choose might depend on your specific situation.

  • One method is to use the doctype definition as in this example:

    <!DOCTYPE log4j:configuration SYSTEM "jar:file:        
    <absolute-path>/log4j.jar!/org/apache/log4j/xml/log4j.dtd">


    The problem with this way is that you have to specify an absolute path to the JAR file, and this might be a problem if you plan to push your project EAR to different servers.
  • Another method is to use the XML catalog. In order to use the jar, URI syntax must make an absolute reference to the DTD, and you can do this by using the XML catalog. Using the catalog, you can register the absolute location of the DTD without extracting it or making an absolute reference in the XML configuration file.
    In order to use the catalog follow these steps:
    1. Open Window > Preferences > Web and XML > XML Catalog.
    2. On the XML Catalog preference page select New. . .
    3. Enter a key of log4j.dtd. The Key type should be Public ID. The URI should be the absolute location of the DTD using the JAR notation that was used in the XML configuration file. For example, it looks like the following:
    4. Select OK in the dialog and again on the preference page.
    5. Change the declaration in the configuration file from the JAR reference to

      <!DOCTYPE log4j:configuration PUBLIC "log4j.dtd" "log4j.dtd">

      The XML configuration file should now validate successfully without extracting the DTD or making an absolute reference in the file.
    This last technique simply allows the tools to locate the required DTD. If it helps, you can also point to a log4j.jar file that is not in the workspace and therefore not included in any specific project.



    [{"Product":{"code":"SSRTLW","label":"Rational Application Developer for WebSphere Software"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Web Development","Platform":[{"code":"PF016","label":"Linux"},{"code":"PF033","label":"Windows"}],"Version":"6.0;6.0.0.1;6.0.1.0;6.0.1.1","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}},{"Product":{"code":"SSYK2S","label":"Rational Software Architect Designer"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Web Development","Platform":[{"code":"PF033","label":"Windows"}],"Version":"6.0;6.0.0.1","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}},{"Product":{"code":"SSJM4G","label":"Rational Web Developer for WebSphere Software"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Web Development","Platform":[{"code":"PF033","label":"Windows"}],"Version":"6.0;6.0.0.1","Edition":"","Line of Business":{"code":"","label":""}}]

    Document Information

    Modified date:
    10 September 2020

    UID

    swg21233092