---
title: "验证log4j.xml时不能找到log4j.dtd"
author: "infoplat"
date: "2011-03-24T13:51:01Z"
tags: ["Apache", "Eclipse", "Myeclipse", "XML", "log4j"]
categories: ["编程语言"]
slug: "log4j-xml-log4j-dtd"
draft: false
lastmod: "2011-03-24T13:51:01Z"
id: 973930
url: "https://suyuening.iteye.com/blog/973930"
---

**问题描述：**  
当使用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验证其格式的有效性"&lt;!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"&gt;"，而系统或项目中找不到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-&gt;Myeclipse-&gt;Files and Editors-&gt;XML-&gt;XML Catalog"定义一个User Specified Entries，Location指定为catalog-dtd下的log4j.dtd，Key Type选"System ID"，Key填"log4j.dtd"，然后执行“Project--&gt;Clean”命令。

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

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