Eclipse log4j.xml – log4j.dtd cannot be validated as the XML definition

Filed Under: Java

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.

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 file cannot be validated as the XML definition “/Users/pankaj/workspace/MyProject/src/main/java/log4j.dtd (No such file or directory)” that is specified as describing the syntax of the file cannot be located.

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 
          "http://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" 
	"http://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.

Leave a Reply

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

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages