Accepted answer

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

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).


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 


i have tried with frvabe's answer but didn't work for me and i did an small change in the key value and it works.

"preferences -> xml -> xml catalog"

localization: c:\users\me\desktop\log4j.dtd
key type: uri
key: -//apache//dtd log4j 1.2//en


@jack leow uses a good approach with the public id. yet, as he points out, it requires a network connection.

i prefer a combination:

entry element:      public
location:           org\apache\log4j\xml\log4j.dtd in jar file c:\development\lib\external\apache-log4j-1.2.17\log4j-1.2.17.jar
uri:                jar:file:/c:/development/lib/external/apache-log4j-1.2.17/log4j-1.2.17.jar!/org/apache/log4j/xml/log4j.dtd
key type:           public id
key:                -//apache//dtd log4j 1.2//en

this references a local jar, and supports a doctype declaration without the full url.

<!doctype log4j:configuration public "-//apache//dtd log4j 1.2//en" "log4j.dtd">


if you place the log4j.dtd at the same location as your log4j.xml, the declaration

<!doctype log4j:configuration system "log4j.dtd">

is good for eclipse (at least eclipse 2020-06).

btw: the eclipse error does not disappear immediately, but it disappears after doing some edits within the log4j.xml file.


i added dtd folder in webcontent and then i copied the log4j dtd file in that. then i tried like bellow. its working

<!doctype log4j:configuration system "<path>/dtd/log4j.dtd">

path means here the project path like /projectname


try to add the log4j.dtd as a user specific uri xml catalog entry in "preferences -> xml -> xml catalog". as i know this is the place where eclipse manages the references to definition/validation files (like xsd). if they can be found here eclipse needs no internet access to access them on their native (web) location.

i did it like this (for test) and eclipse does not complain:

entry element:    uri
location:         c:\users\me\desktop\log4j.dtd
uri:              file:///c:/users/me/desktop/log4j.dtd
key type:         uri

maybe also ${m2_repo} works - i did not check this.

use the native url in your log4j.xml afterwards

<!doctype log4j:configuration system "">


i would go with the above solution but to come back to your question, i think class path variables 'can be used in a java build path'. why should they work inside a doctype definition? "validate" (eclipse context menu) the log4j.xml file and you will get a warning that the path can not be resolved.

i hoped classpath:org/apache/log4j/xml/log4j.dtd would do the trick but that protocol is also not support (see validation error). i am afraid it will not work out of the box.

and, as i understood, the system "log4j.dtd" notation is no placeholder. it is a valid reference to a document that is expected to be found next to the dtd (in this case).

Related Query

More Query from same tag