Eclipse: Referencing log4j.dtd in log4j.xml

sjngm picture sjngm · Feb 15, 2011 · Viewed 88k times · Source

I've been using log4j for quite a while now and I usually use this at the top of the log4j.xml (probably just like many others and according to Google this is the way to do it):

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

Obviously this is working, however Eclipse doesn't provide its context-sensitive help for writing the XML and all. Furthermore, it always shows a warning that it doesn't find the log4j.dtd. Now I'm curious how to fix this.

I tried a few things and these work:

<!DOCTYPE log4j:configuration SYSTEM "jar:file:/path/.m2/repository/log4j/log4j/1.2.14/log4j-1.2.14.jar!/org/apache/log4j/xml/log4j.dtd">
<!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">

As you can see from above we're using Maven. Therefore, I tried this, but it fails:

<!DOCTYPE log4j:configuration SYSTEM "jar:file:${M2_REPO}/log4j/log4j/1.2.14/log4j-1.2.14.jar!/org/apache/log4j/xml/log4j.dtd">

Eclipse usually knows how to deal with the classpath variables, but why doesn't this work? I know that the reference won't work during runtime, but neither does a simple log4j.dtd (if I'm not wrong), so that shouldn't be a problem.

Can anyone please shed a light on this?

Answer

Jack Leow picture Jack Leow · Jun 1, 2012

I know this question has been answered, but I'd like to provide my slightly different alternative:

<!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">

It is similar to @FrVaBe's response, but on the plus side, does not require any further Eclipse configuration (i.e., if you're sharing your project with others, or have a large team, it's one less thing to worry about).

The down side though, is that I believe it means you'll need an Internet connection (at least at some point during development, even if it's just one time).