当我尝试使用PDFBox示例之一提取图像时,在运行时出现以下异常:

   Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at org.apache.pdfbox.pdfparser.BaseParser.<clinit>(BaseParser.java:68)
    at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1218)
    at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1186)
    at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1111)
    at pdfboxtest.PdfBoxTest.extractImage(PdfBoxTest.java:69)
    at pdfboxtest.PdfBoxTest.main(PdfBoxTest.java:53)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    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)
    ... 6 more

这是最后两行中发生异常的代码部分:
         String pdfFile = "pdf file path";
         File pdf=new  File(pdfFile);
         PDDocument document = null;
         document = PDDocument.loadNonSeq(pdf, null, password);
         document = PDDocument.load( pdfFile );

最佳答案

添加commons-logging-1.1.1.jar
或者
您的lib目录中的jcl-over-slf4j-1.7.6.jar。

关于java - 尝试使用pdfBox时出现.NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28164121/

10-10 20:19