ParserConfigurationException while using log4j2 with junit
Asked Answered
S

1

8

I am using junit 4.10 and log4j2 2.10 version

I am getting the following exception, which I am unable to figure out

ERROR StatusLogger Error parsing /scratch/log4j.xml
javax.xml.parsers.ParserConfigurationException
    at oracle.xml.jaxp.JXDocumentBuilderFactory.setFeature(JXDocumentBuilderFactory.java:374)
    at org.apache.logging.log4j.core.config.xml.XmlConfiguration.setFeature(XmlConfiguration.java:213)
    at org.apache.logging.log4j.core.config.xml.XmlConfiguration.disableDtdProcessing(XmlConfiguration.java:205)
    at org.apache.logging.log4j.core.config.xml.XmlConfiguration.newDocumentBuilder(XmlConfiguration.java:194)
    at org.apache.logging.log4j.core.config.xml.XmlConfiguration.<init>(XmlConfiguration.java:92)
    at org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory.getConfiguration(XmlConfigurationFactory.java:46)
    at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:417)
    at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:346)
    at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:260)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:613)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:634)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:229)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:243)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:174)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:648)
    at oracle.oki.service.SampleBaseTest.<clinit>(SampleBaseTest.java:53)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:337)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:931)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:785)
    ERROR StatusLogger No logging configuration

I am able to use the same configuration file with standalone programs and that goes through fine.

Super answered 19/3, 2018 at 10:56 Comment(0)
A
6

JRE detects XML parser from Oracle XML library xmlparserv2.jar as default. Oracle parser doesn't support features required by log4j.

It is possible to force JRE to use default XML parser from JRE

  • Either; System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
  • or use -D runtime param; -Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
Arsenide answered 8/12, 2021 at 9:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.