【转】验证log4j.xml时不能找到log4j.dtd

问题描述:
当使用log4j.xml配置日志时,Myeclipse验证该xml文件时,出现警告"The file cannot be validated as the XML Schema "D:\workspace\Log4jDemo\src\log4j.dtd (系统找不到指定的文件。)" that is specified as describing the syntax of the file cannot be located."

原因分析:
log4j.xml中使用log4j的DTD验证其格式的有效性"<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">",而系统或项目中找不到log4j.dtd,因此出现以上警告。

解决方法:
使用解压缩工具解压log4j.jar文件,找到org/apache/log4j/xml目录下的log4j.dtd文件。

方法1.将log4j.dtd拷贝到Myeclipse的dtd目录(Myeclipse8.5位于Genuitec\Common\plugins\com.genuitec.eclipse.j2eedt.core_8.5.0.me201003231033\catalog-dtd,Myeclipse6.6位于MyEclipse 6.6\myeclipse\eclipse\plugins\com.genuitec.eclipse.j2eedt.core_6.6.0.zmyeclipse660200810\catalog-dtd)中,然后通过"Preferences->Myeclipse->Files and Editors->XML->XML Catalog"定义一个User Specified Entries,Location指定为catalog-dtd下的log4j.dtd,Key Type选"System ID",Key填"log4j.dtd",然后执行“Project-->Clean”命令。

方法2.将log4j.dtd拷贝到项目的src目录下,执行“Project-->Clean”命令。

推荐使用方法1,一劳永逸,对所有项目均有效。

猜你喜欢

转载自jsycjacky.iteye.com/blog/1911961