问题描述
我已经使用 log4j 有一段时间了,我通常在 log4j.xml 的顶部使用它(可能就像许多其他人一样,根据谷歌,这是的方法它):
I've been using log4j for quite a while now and I usually use this at the top of the log4j.xml (probably just like many others and according to Google this is the way to do it):
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
显然这是有效的,但是 Eclipse 没有为编写 XML 和所有内容提供上下文相关的帮助.此外,它始终显示未找到 log4j.dtd
的警告.现在我很好奇如何解决这个问题.
Obviously this is working, however Eclipse doesn't provide its context-sensitive help for writing the XML and all. Furthermore, it always shows a warning that it doesn't find the log4j.dtd
. Now I'm curious how to fix this.
我尝试了一些方法,这些方法奏效了:
I tried a few things and these work:
<!DOCTYPE log4j:configuration SYSTEM "jar:file:/path/.m2/repository/log4j/log4j/1.2.14/log4j-1.2.14.jar!/org/apache/log4j/xml/log4j.dtd">
<!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
正如您从上面看到的,我们使用的是 Maven.因此,我尝试了这个,但失败了:
As you can see from above we're using Maven. Therefore, I tried this, but it fails:
<!DOCTYPE log4j:configuration SYSTEM "jar:file:${M2_REPO}/log4j/log4j/1.2.14/log4j-1.2.14.jar!/org/apache/log4j/xml/log4j.dtd">
Eclipse 通常知道如何处理类路径变量,但是为什么这不起作用?我知道引用在运行时不起作用,但简单的 log4j.dtd
也不起作用(如果我没记错的话),所以这应该不是问题.
Eclipse usually knows how to deal with the classpath variables, but why doesn't this work? I know that the reference won't work during runtime, but neither does a simple log4j.dtd
(if I'm not wrong), so that shouldn't be a problem.
有人能解释一下吗?
推荐答案
我知道这个问题已经得到解答,但我想提供我稍微不同的替代方案:
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">
它类似于 @FrVaBe 的响应,但从好的方面来说,不需要任何进一步的 Eclipse 配置(即,如果您要与他人共享您的项目,或者拥有一个庞大的团队,则无需担心).
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).
这篇关于Eclipse:在 log4j.xml 中引用 log4j.dtd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!