Java 问题http://apache.org/xml/features/xinclude 测试log4j 2

Java 问题http://apache.org/xml/features/xinclude 测试log4j 2,java,logging,log4j2,Java,Logging,Log4j2,我正在测试Log4j2,我不知道我做错了什么,因为我从Apache下载了这个库并将它们放在类路径中。我还添加了xercesImpl、xalan、XMLAPI、序列化程序和xsltc,异常仍然存在。我将显示堆栈跟踪和配置文件: <?xml version="1.0" encoding="UTF-8"?> <Configuration status="DEBUG"> <Properties> <Property name="log-p

我正在测试Log4j2,我不知道我做错了什么,因为我从Apache下载了这个库并将它们放在类路径中。我还添加了xercesImpl、xalan、XMLAPI、序列化程序和xsltc,异常仍然存在。我将显示堆栈跟踪和配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">
    <Properties>
        <Property name="log-path">C:/Logs/</Property>
    </Properties>
    <Appenders>
        <RollingFile name="RollingFile" fileName="${log-path}/myexample.log"
            filePattern="${log-path}/myexample-%d{yyyy-MM-dd}-%i.log">
            <PatternLayout>
                <pattern>%d{dd/MMM/yyyy HH:mm:ss,SSS}- %c{1}: %m%n</pattern>
            </PatternLayout>
            <Policies>
                <SizeBasedTriggeringPolicy size="1 KB" />
            </Policies>
            <DefaultRolloverStrategy max="4" />
        </RollingFile>
    </Appenders>
    <Loggers>
        <Logger name="root" level="debug" additivity="false">
            <appender-ref ref="RollingFile" level="debug" />
        </Logger>
        <Root level="debug" additivity="false">
            <AppenderRef ref="RollingFile" />
        </Root>
    </Loggers>
</Configuration>


ERROR StatusLogger Error parsing C:\W7des\cliente\Test\bin\log4j2.xml javax.xml.parsers.ParserConfigurationException: Feature 'http://apache.org/xml/features/xinclude' is not recognized.
    at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.newDocumentBuilder(Unknown Source)
    at org.apache.logging.log4j.core.config.xml.XmlConfiguration.newDocumentBuilder(XmlConfiguration.java:85)
    at org.apache.logging.log4j.core.config.xml.XmlConfiguration.<init>(XmlConfiguration.java:137)
    at org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory.getConfiguration(XmlConfigurationFactory.java:44)
    at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:472)
    at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:442)
    at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:254)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:419)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:138)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:207)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:41)
    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:160)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:492)
    at pac.Main.<clinit>(Main.java:14)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)

C:/log/
%d{dd/MMM/yyyy HH:mm:ss,SSS}-%c{1}:%m%n
错误状态记录器错误解析C:\W7des\cliente\Test\bin\log4j2.xml javax.xml.parsers.parserConfiguration异常:功能'http://apache.org/xml/features/xinclude“不被承认。
位于org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.newDocumentBuilder(未知源)
位于org.apache.logging.log4j.core.config.xml.XmlConfiguration.newDocumentBuilder(XmlConfiguration.java:85)
位于org.apache.logging.log4j.core.config.xml.XmlConfiguration.(XmlConfiguration.java:137)
位于org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory.getConfiguration(XmlConfigurationFactory.java:44)
位于org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:472)
位于org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:442)
位于org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:254)
位于org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:419)
位于org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:138)
位于org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:207)
位于org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:41)
位于org.apache.logging.log4j.LogManager.getContext(LogManager.java:160)
位于org.apache.logging.log4j.LogManager.getLogger(LogManager.java:492)
在pac.Main.(Main.java:14)
位于java.lang.J9VMInternals.initializeImpl(本机方法)
在java.lang.J9VMInternals.initialize(J9VMInternals.java:200)中

提前感谢。

Oracle JVM附带了一个支持XInclude的XML解析器。 根据本文档,IBMJ9VM还捆绑了一个支持XInclude的XML解析器(参见第21页XML4J4.5)

我不确定是否有必要使用单独的XML解析器(您提到您使用的是Xerces,而不是JVM捆绑的XML解析器)。 您使用的Xerces/Xalan版本是什么?如果从类路径中删除自定义XML解析器,会发生什么

顺便说一下,如果Log4j不能启用XInclude,它将输出警告级别的StatusLogger消息。 您是否收到任何以“DocumentBuilderFactory…”开头的警告级别状态记录器消息?请在您的问题中包含这些信息


不幸的是,目前Log4j中没有开关来阻止它尝试启用XInclude功能。我怀疑上面的问题是一个配置问题,但是如果无法解决,您可以请求添加这样一个开关作为新的Log4j特性。这个地方是Log4j。

在我的例子中,从类路径中删除过时的
xercesImpl-2.6.2.jar
有帮助。

在从gradle缓存中删除xerces目录后对我起了作用

cd ~/.gradle/caches/modules-2/files-2.1
rm -rf xerces

首先,我在没有任何附加库的情况下进行了测试,错误也是一样的。然后,我使用了Xerces(2.11)和Xalan(2.7.1)的最新版本。虽然我去掉了它们,但问题仍然存在。我在控制台中看到的唯一消息是:
ERROR StatusLogger ERROR parsing C:\W7des\cliente\Test\bin\log4j2.xml javax.xml.parsers.ParserConfigurationException:Feature'http://apache.org/xml/features/xinclude“不被承认。错误状态记录器没有日志记录配置
,但异常是关于DocumentBuilderFactory的…我询问警告的原因是,如果
DocumentBuilderFactory.setXIncludeAware(true)
由于某种原因失败,Log4j将输出警告消息。。。另请参见:我将属性设置为“true”,但没有收到任何新消息。。。我认为问题出在
org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.newDocumentBuilder(未知源代码)
。我还能做什么?我只是解决了问题。我有一些项目添加到我的实际项目中,他们有一些库,这些库使我的应用程序在新的log4j2中崩溃。我想我必须再次选择库以避免不一致。谢谢大家。很高兴听到这个消息。配置问题有时可能是一个真正的棘手问题来解决…确认-对我来说也很有效,用xercesImpl 2.11.0版替换了相关的依赖项,错误消失了。谢谢或者在我将-D建议添加到gradlew build clean-D时,将
-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.documentbuilderfactorympl
添加到jvm参数中。。。。。。。。。。。这没什么区别。