score:185
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).
score:0
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">
score:1
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
score:1
@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">
score:1
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.
score:2
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
score:41
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
Key: http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd
Maybe also ${M2_REPO} works - I did not check this.
Use the native URL in your log4j.xml afterwards
<!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
EDIT
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).
Source: stackoverflow.com
Related Query
- Suppress XML DTD error in Eclipse
- XML DTD Validate. Difference in Eclipse and other editors
- XML not validating in Eclipse with external DTD
- Can you run xmllint within eclipse to validate xml and dtd files?
- Disable XML validation in Eclipse
- Format XML code in Eclipse
- Eclipse can't find XML related classes after switching build path to JDK 10
- No line numbers in Eclipse or Android Studio XML editor
- How to stop Eclipse from trying to run XML files?
- How to configure Eclipse XML formatting?
- Eclipse shortcut for commenting jsp, xml code
- Eclipse Run button doesn't work when Android xml file is selected
- Best XML editor for Eclipse
- Bogus Eclipse warning for web.xml: "No grammar constraints (DTD or XML schema) detected for the document."
- Log4j output not displayed in Eclipse console
- eclipse xml editor inserts tabs for spaces
- Using a XML File (log4j2.xml) to configure Log4j 2
- Howto prevent eclipse from line wrapping in XML and HTML files?
- Eclipse shortcut to comment selection in an XML file
- Android project referencing "normal" java project in eclipse since sdk tools update 17
- ADT eclipse xml layout text editor - often broken until file closed and reopened
- Eclipse Android XML jumps around the editor
- eclipse on maven project warning 'DTD or XML schema'
- Android: Eclipse autocomplete does not work in xml files
- How do I jump to XML resources in Eclipse instead of R.java
- better Android XML Layout Editor than the one in Eclipse
- Eclipse and Android XML layouts gives "'default' is not a best match for any device/locale combination"
- Eclipse load data from 2.3 to 4.4 every time you open an xml file
- Eclipse doesn't put XML files in project's own buildpath
- Eclipse IDE - Android Graphical Layout and XML Layout Side by Side
More Query from same tag
- keyboard not coming up
- Have a Java application (JAR) that needs to be executable. (Built In Eclipse)
- Java Eclipse plugin Development - Save all project's files programmatically
- How to display a Hierarchy (Java)
- Adding shared library to websphere server application in eclipse luna
- Eclipse j2me json parsing
- How to change terminal font color in Spring Tools 4 for Eclipse
- Class has virtual method but non virtual destructor C++
- Private field in parent class shadowed/hidden by subclass - inspections to catch it
- Putting JPanels with colored borders in a specific order so they look like a grid
- NoClassDefFoundError when referencing from an Android-Project to a standard Java-Project
- How to get a folder in eclipse to refresh its content or use external folder
- Subclipse synchronisation history?
- BaseGameActivity won't be found
- Eclipse - won't add svn repository
- Failed to create the part's controls in Eclipse Mars error
- Selenium junit tests - how do I run tests within a test in sequential order?
- Eclipse HTTP server null pointer exception
- Android change SDK version in Eclipse? Unable to resolve target android-x
- Eclipse 3.7, m2eclipse & losing artifacts after changing pom.xml
- Can I create an Eclipse Project that produces multiple executable Jars?
- Extracting Common Java Package
- aspectj: How to weave aspects from a library into user code?
- Interstitials showing outside app
- Eclipse can't parse heap dump
- maven command to copy dependencies into eclipse project
- How can I extend Eclipse Java search to JSPs?
- Missing xml config tabs in Eclipse?
- Eclipse is very slow when using Code Assist (org.eclipse.mylyn.java.ui.javaAllCompletionProposalComputer)
- Unable to read repository at https://testng.org/testng-eclipse-update-site