简体   繁体   English

NullPointerException与带有Maven的log4j

[英]NullPointerException with log4j with maven

I have main pom, and two modules (sub poms), first of them contains dependency to log4j. 我有主pom和两个模块(子poms),其中第一个包含对log4j的依赖关系。 First module - some utility classes. 第一个模块-一些实用程序类。 Second - tests for first module (jcstress) that compiles to sub-jar using shade plugin. 第二个-测试第一个模块(jcstress),该模块使用shade插件编译为sub-jar。 compilation works fine, but then run tests (second module), it fails with this error. 编译工作正常,但随后运行测试(第二个模块),它将失败并显示此错误。 I have to dependencies for log4j in first module and they are copied to second one: 我必须在第一个模块中使用log4j的依赖项,并将它们复制到第二个模块中:

   <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.11.0</version>
    </dependency>

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.11.0</version>
    </dependency> 

Exception in thread "main" java.lang.ExceptionInInitializerError at avalsa.util.ConcurrentSortedLinkedList.(ConcurrentSortedLinkedList.java:12) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at org.openjdk.jcstress.util.Reflections.getClasses(Reflections.java:64) at org.openjdk.jcstress.vm.ContendedTestMain.main(ContendedTestMain.java:44) Caused by: java.lang.NullPointerException at org.apache.logging.log4j.util.LoaderUtil.getClassLoaders(LoaderUtil.java:115) at org.apache.logging.log4j.util.ProviderUtil.(ProviderUtil.java:66) at org.apache.logging.log4j.util.ProviderUtil.lazyInit(ProviderUtil.java:146) at org.apache.logging.log4j.util.ProviderUtil.hasProviders(ProviderUtil.java:130) at org.apache.logging.log4j.LogManager.(LogManager.java:89) ... 5 more avalsa.util.ConcurrentSortedLinkedList。(ConcurrentSortedLinkedList.java:12)处的线程“ main”中的java.lang.ExceptionInInitializerError异常,java.lang.Class.forName0(本机方法)处java.lang.Class.forName(Class.java: 264)at org.openjdk.jcstress.util.Reflections.getClasses(Reflections.java:64)at org.openjdk.jcstress.vm.ContendedTestMain.main(ContendedTestMain.java:44)由以下原因导致:org的java.lang.NullPointerException org.apache.logging.log4j.util.ProviderUtil。(ProviderUtil.java:66)上的.apache.logging.log4j.util.LoaderUtil.getClassLoaders(LoaderUtil.java:115)在org.apache.logging.log4j.util。 org.apache.logging.log4j.util.ProviderUtil.hasProviders(ProviderUtil.java:130)的org.apache.logging.log4j.LogManager。(LogManager.java:89)的ProviderUtil.lazyInit(ProviderUtil.java:146)。 ..另外5个

Any ideas? 有任何想法吗?

Remove log4j dependency in your POM and Add this dependency 删除POM中的log4j依赖项并添加此依赖项

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.12</version>
        </dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM