I use log4j in most of the projects for logging and use XML based configuration. Most of the part in log4j.xml
is common and all we need to add appenders and loggers.
Table of Contents
Eclipse log4j.xml – log4j.dtd cannot be validated as the XML definition
Recently Eclipse shown a warning in my log4j.xml file as below. However it had no effect on my project build or deployment.
The line that was throwing the error was:
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
Fix for Eclipse log4j.xml – log4j.dtd cannot be validated as the XML definition
Usually Eclipse looks for log4j.dtd in classpath and it doesn’t find it there and hence the error. We can resolve this issue by providing URL for log4j.dtd file like below.
<!DOCTYPE log4j:configuration SYSTEM
"https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
Some other valid configuration through which we can resolve the warning is:
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN"
"https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
That’s all for fixing this eclipse log4j xml error because of log4j.dtd location.