Hi All,
Could someone advise if this is the proper way to use PDFBox without Maven?
There are many users who are not familiar with Maven. I have downloaded
pdfbox-1.1.0.jar, fontbox-1.1.0.jar, and jempbox-1.1.0.jar from
http://pdfbox.apache.org/download.html
I added all three jars to my classpath and compiled the following program
import java.io.*;
import org.apache.pdfbox.pdmodel.*;
import org.apache.pdfbox.util.*;
public class PDFTest {
public static void main(String[] args){
PDDocument pd;
BufferedWriter wr;
try {
File input = new File("C:\\invoice.pdf");
File output = new File("C:\\Text.txt");
pd = PDDocument.load(input);
PDFTextStripper stripper = new PDFTextStripper();
wr = new BufferedWriter(new OutputStreamWriter(new
FileOutputStream(output)));
stripper.writeText(pd, wr);
if (pd != null) {
pd.close();
}
} catch (Exception e){
e.printStackTrace();
}
}
}
It compiles fine but I receive the following error messages when I run it.
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/commons/logging/LogFactory
at org.apache.pdfbox.pdfparser.BaseParser.<clinit>(BaseParser.java:58)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:846)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:814)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:785)
at PDFTest.main(PDFTest.java:13)
Caused by: java.lang.ClassNotFoundException:
org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 5 more
When I add commons-logging-1.1.1.jar in the classpath it works fine. Does
this mean that commons-logging-1.1.1.jar has to be included in the classpath
in addition to the already listed jars?
Thanks in advance,
Stephen