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

来源:互联网 发布:js让多个功能延迟执行 编辑:程序博客网 时间:2024/05/22 17:49

在使用spring tools suite布置Maven项目过程中,log4j.xml中报如下错误,报错信息如下:

Referenced file contains errors (http://toolkit.alibaba-inc.com/dtd/log4j/log4j.dtd). For more 
 information, right click on the message in the Problems View and select "Show Details...

以下是老外的解决方案,成功解决该该报错信息:

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.

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:

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

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.

1
2
<!DOCTYPElog4j: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:

<!DOCTYPElog4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN"
    "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">

0 0