Home / Java / Resolving log4j.dtd error on JBoss

Resolving log4j.dtd error on JBoss

I recently faced an issue where the application was not able to find the log4j.dtd, when deployed on jboss. We were using our own repository selector for logging and an isolated classloader. But could see a “FileNotFoundException” for log4j.dtd in the JBoss log when the application was deployed, although the dtd was part of the log4j jar contained within the application. The reason for that was the xml parser was not looking in the classpath resources for the dtd, but was just looking in a path relative to the application’s root directory.

Now in order to load the dtd from the classpath I updated the repository selector and set an EntityResolver to the DocumentBuilder so that when the parser encounters the dtd reference the resolver looks it up from the classpath. Here is the code to that.

Assuming that the doctype reference in log4j.xml is:

The code to override the default behavior of the parser to look for the dtd in the classpath:

Now our EntityResolver will return the dtd from classpath whenever the parser encounters it. Although I wish the parser could support the “classpath” protocol in the doctype uri.

About Author:

2 thoughts on “Resolving log4j.dtd error on JBoss

Leave A Comment

Your email address will not be published. Required fields are marked *