在计算目录中MP4文件的总持续时间时SLF4J出现问题

时间:2015-08-31 19:38:05

标签: java maven jar slf4j

主要目标:

我的主要目标是从目录中获取所有.mp4个文件的持续时间。所以,我搜索了它并找到了this qeustion,其中一个答案提到了this完整代码。

导入错误:

当我在代码中取得必要的部分时,它在以下行中显示错误:

import com.xuggle.xuggler.IContainer;

之后,我从here下载了来自here的Xuggler。然后我得到以下错误:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at com.xuggle.ferry.JNILibrary.<clinit>(JNILibrary.java:42)
    at com.xuggle.ferry.FerryJNI.<clinit>(FerryJNI.java:14)
    at com.xuggle.ferry.Ferry.<clinit>(Ferry.java:25)
    at com.xuggle.xuggler.XugglerJNI.<clinit>(XugglerJNI.java:19)
    at com.xuggle.xuggler.IContainer.<clinit>(IContainer.java:1622)
    at videotimecalcualtioncoursera.MainFrame.calculateTime(MainFrame.java:116)
    at videotimecalcualtioncoursera.MainFrame.jButtonCalculateActionPerformed(MainFrame.java:284)
    at videotimecalcualtioncoursera.MainFrame.access$000(MainFrame.java:33)
    at videotimecalcualtioncoursera.MainFrame$4.actionPerformed(MainFrame.java:204)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6525)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
    at java.awt.Component.processEvent(Component.java:6290)
    at java.awt.Container.processEvent(Container.java:2234)
    at java.awt.Component.dispatchEventImpl(Component.java:4881)
    at java.awt.Container.dispatchEventImpl(Container.java:2292)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
    at java.awt.Container.dispatchEventImpl(Container.java:2278)
    at java.awt.Window.dispatchEventImpl(Window.java:2739)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)
    at java.awt.EventQueue.access$400(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:697)
    at java.awt.EventQueue$3.run(EventQueue.java:691)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:719)
    at java.awt.EventQueue$4.run(EventQueue.java:717)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:716)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 45 more

解决异常&#34; java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory&#34;:

为了寻求上述例外的解决方案,我找到了this question并尝试了所有三个解决方案而没有运气。得到以下例外:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006ee76520, pid=10112, tid=3292
#
# JRE version: Java(TM) SE Runtime Environment (8.0_25-b18) (build 1.8.0_25-b18)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.25-b02 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  [xuggle6026878147022032067.dll+0x736520]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# H:\Dropbox\JavaProjects\VideoTimeCalcualtionCoursera\hs_err_pid10112.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Java Result: 1

解决异常&#34; SLF4J:无法加载类&#34; org.slf4j.impl.StaticLoggerBinder&#34;:

求它的解决方案,我得到this question并且接受的答案除了删除错误流中的前三行外什么都不做。

我当时尝试过:

我尝试在我的项目中添加以下.jar文件:

  1. xuggle-xuggler-5.4.jar
  2. slf4j-api-1.6.4.jar / slf4j-api-1.7.12.jar
  3. slf4j-simple-1.7.6.jar / slf4j-simple-1.7.12.jar
  4. 的log4j-1.2.16.jar
  5. 的logback-经典1.0.0.jar
  6. 的logback核-1.0.6.jar
  7. SLF4J-jdk14-1.7.12.jar
  8. SLF4J-log4j12-1.7.12.jar
  9. 文件 - hs_err_pid10112.log:

    您可以看到错误文件here,我无法添加它,因为添加它会越过字符限制。

    如何解决此问题?

    注意:

    我已经遍历了以下问题:

    1. using Logback with slf4j [on hold]
    2. Error with Slf4j and classpath
    3. Given I'm stuck with SLF4J and java.util.Logging, what is optimal solution?
    4. How do I get a list of configured loggers using Jboss LogManager with SLF4J?
    5. How to write event logs into xml files with SLF4J or Logback?
    6. OpenJPA logging with slf4j on WebSphere
    7. Tomcat Logging With Slf4j and Log4j

3 个答案:

答案 0 :(得分:1)

您通常需要三个功能部分:

  1. 程序使用的API(slf4j-api)
  2. 桥接代码以使记录器实现适应SLF4J API(例如slf4j-log4j12),这个必须与您使用的记录器匹配。
  3. 记录器实现(例如log4j)
  4. 有些罐子覆盖多个部分,例如: logback包含2和3,因为它本机实现了slf4j,或者如果使用java util日志,则不需要显式添加第3部分(它位于Java运行时)

    您还必须使用slf4j组件的匹配版本,例如,不要将slf4j-api-1.6.4.jar与slf4j-log4j12-1.7.12.jar混合使用。

    详细了解slf4j documentation

答案 1 :(得分:0)

我会尝试逐个添加您的依赖项(同时注释掉依赖代码)。我的第一印象是其中一个库在类路径上为slf4j提供了不兼容的版本/后端。在你发现这一点之前,我们无法知道哪一个。完成后,您可以让gradle / maven从类路径中排除一个冲突的东西。

答案 2 :(得分:0)

我无法解决问题,但我可以通过其他方式实现我的目标。

我已经使用了IBM的工具包。

  1. here下载IBM的API。
  2. 在我的代码中添加了以下代码段:

    public long getDuration(File file) throws IOException {
        PlayerControl playerControl = PlayerFactory.createLightweightMPEG4Player();
        playerControl.open(file.getAbsolutePath());
        return playerControl.getDuration();
    }
    
  3. 由于我的目标只是获得持续时间,这不是有效的方式。

    在我的PC(core-i5,2.5GHz,6GB内存,Win10)中,42657ms处理了60个.mp4文件输出大约6小时41分钟的持续时间

    如果需要,可以在my repository中查看。