Java 在类路径上检测到 log4j-over-slf4j.jar 和 slf4j-log4j12.jar,抢占 StackOverflowError。

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20117720/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 23:16:50  来源:igfitidea点击:

Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError.

javajar

提问by Yuvraj Kakkar

I have used xuggle libraryin my project to trans code the video from mp4 to flv. I have used slf4j librariesalso to support logging end.

xuggle library在我的项目中使用了从mp4 to flv. 我也用过slf4j libraries支持日志记录结束。

import com.xuggle.mediatool.IMediaReader;
import com.xuggle.mediatool.IMediaViewer;
import com.xuggle.mediatool.IMediaWriter;
import com.xuggle.mediatool.ToolFactory;

public class TranscodingExample {

    private static final String inputFilename = "E:\VIDEO\Facebook.mp4";
    private static final String outputFilename = "E:\VIDEO\Facebook.flv";

    public static void main(String[] args) {

        // create a media reader
        IMediaReader mediaReader = 
               ToolFactory.makeReader(inputFilename);

        // create a media writer
        IMediaWriter mediaWriter = 
               ToolFactory.makeWriter(outputFilename, mediaReader);

        // add a writer to the reader, to create the output file
        mediaReader.addListener(mediaWriter);

        // create a media viewer with stats enabled
        IMediaViewer mediaViewer = ToolFactory.makeViewer(true);

        // add a viewer to the reader, to see the decoded media
        mediaReader.addListener(mediaViewer);

        // read and decode packets from the source file and
        // and dispatch decoded audio and video to the writer
        while (mediaReader.readPacket() == null) ;

    }

}

Here I am getting an error

在这里我收到一个错误

"Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError.". 

I have used both jar files as libraries in order to solve logging problems. Does any one faced the same problem.If so kindly write suggestion or solution to come out of this mess. Thanks in advance.

为了解决日志记录问题,我使用了两个 jar 文件作为库。有没有人遇到同样的问题。如果是这样,请写出建议或解决方案以摆脱困境。提前致谢。

采纳答案by Tomas Hanus

So you have to exclude conflict dependencies. Try this:

所以你必须排除冲突依赖。尝试这个:

<exclusions>
  <exclusion> 
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
  </exclusion>
  <exclusion> 
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
  </exclusion>
</exclusions> 

This solved same problem with slf4j and Dozer.

这解决了与 slf4j 和 Dozer 相同的问题。

回答by Stephen C

You asked if it is possible to change the circular dependency checking in those slf4j classes.

您询问是否可以更改这些 slf4j 类中的循环依赖项检查。

The simple answer is no.

简单回答是不。

  • It is unconditional ... as implemented.
  • It is implemented in a staticinitializer block ... so you can't override the implementation, and you can't stop it happening.
  • 它是无条件的......正如实施的那样。
  • 它是在static初始化块中实现的……所以你不能覆盖实现,也不能阻止它发生。

So the only way to change this would be to download the source code, modify the core classes to "fix" them, build and use them. That is probably a bad idea (in general) and probably not solution in this case; i.e. you risk triggering the stack overflow problem that the message warns about.

所以改变这一点的唯一方法是下载源代码,修改核心类以“修复”它们,构建和使用它们。这可能是一个坏主意(一般来说),在这种情况下可能不是解决方案;即您有触发消息警告的堆栈溢出问题的风险。

Reference:

参考:



The real solution (as you identified in your Answer) is to use the right JARs. My understanding is that the circularity that was detected is real and potentially problematic ... and unnecessary.

真正的解决方案(如您在答案中所确定的)是使用正确的 JAR。我的理解是,检测到的循环是真实的,并且可能有问题……而且是不必要的。

回答by Yuvraj Kakkar

I got the solution

我得到了解决方案

download Xuggler 5.4 here

在这里下载 Xuggler 5.4

and some more jar to make it work...

还有一些罐子让它工作......

commons-cli-1.1.jar

commons-cli-1.1.jar

commons-lang-2.1.jar

commons-lang-2.1.jar

logback-classic-1.0.0.jar

logback-classic-1.0.0.jar

logback-core-1.0.0.jar

logback-core-1.0.0.jar

slf4j-api-1.6.4.jar

slf4j-api-1.6.4.jar

Reference Libraries

参考图书馆

You can check which dependencies xuggler needs from here:

您可以从这里检查 xuggler 需要哪些依赖项:

Add this jars and xuggle-xuggler-5.4.jar to your project's build path and it s ready.

将此 jars 和 xuggle-xuggler-5.4.jar 添加到项目的构建路径中,它就准备好了。

**version numbers may change

**版本号可能会改变

回答by okwap

For gradle

对于 gradle

compile('org.xxx:xxx:1.0-SNAPSHOT'){
    exclude module: 'log4j'
    exclude module: 'slf4j-log4j12'
}

回答by Dun0523

Encountered a similar error, this how I resolved it:

遇到了类似的错误,我是这样解决的:

  1. Access Project explorer view on Netbeans IDE 8.2. Proceed to your project under Dependencies hover the cursor over the log4j-over-slf4j.jar to view the which which dependencies have indirectly imported as shown below. enter image description here

  2. Right click an import jar file and select Exclude Dependency enter image description here

  3. To confirm, open your pom.xml file you will notice the exclusion element as below.
  1. 访问 Netbeans IDE 8.2 上的项目资源管理器视图。在依赖项下继续到您的项目,将光标悬停在 log4j-over-slf4j.jar 上以查看哪些依赖项已间接导入,如下所示。 在此处输入图片说明

  2. 右键单击导入 jar 文件并选择排除依赖项 在此处输入图片说明

  3. 要确认,请打开您的 pom.xml 文件,您将看到如下所示的排除元素。

enter image description here4. Initiate maven clean install and run your project. Good luck!

在此处输入图片说明4. 启动 maven 全新安装并运行您的项目。祝你好运!

回答by Ismail H

And for SBT : excludeDependencies += "log4j" % "log4j"

而对于 SBT : excludeDependencies += "log4j" % "log4j"

回答by Arosha

SBT solution stated above did not work for me. What worked for me is excluding slf4j-log4j12

上面提到的 SBT 解决方案对我不起作用。对我有用的是排除slf4j-log4j12

//dependencies with exclusions
libraryDependencies ++= Seq(
    //depencies
).map(_.exclude("org.slf4j","slf4j-log4j12"))