.NoClassDefFoundError when trying to use pdfBox

2019-02-22 14:59发布

when I try to use one of the PDFBox examples for extracting images, in the run time,it gives me the following exception:

   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

here is the part of the code that exception occurs, at the last two lines:

         String pdfFile = "pdf file path";
         File pdf=new  File(pdfFile);
         PDDocument document = null;
         document = PDDocument.loadNonSeq(pdf, null, password);
         document = PDDocument.load( pdfFile );

4条回答
淡お忘
2楼-- · 2019-02-22 15:41

Add the required dependency to your class-path (from the link)

The main PDFBox component, pdfbox, has a hard dependency on commons-logging

查看更多
够拽才男人
3楼-- · 2019-02-22 15:45

Download jar file from the following Link. Add it to your class path.

查看更多
Summer. ? 凉城
4楼-- · 2019-02-22 15:49

Add commons-logging-1.1.1.jar or jcl-over-slf4j-1.7.6.jar in your lib directory.

查看更多
The star\"
5楼-- · 2019-02-22 15:59

For someone using PDFBox 2.0.4, you need to add debugger-app-2.0.4.jar in your Libraries directory

查看更多
登录 后发表回答