Reputation: 123
I am trying to use pdfbox to write a simple pdf file but the problem is that I am getting error :
cannot find symbol class PDDocument
I have downloaded the jar files into the same folder the program exists. How to fix this compilation error?
package org.apache.pdfbox.pdmodel.PDDocument;
import java.io.*;
import org.apache.pdfbox.pdmodel.PDDocument;
public class pdf
{
public static void main(String args[])
{
}
}
Upvotes: 12
Views: 68219
Reputation: 471
having a similar issue I found that I did not have the correct syntax on the import line in the java source
doing a compile as the following (on windows):
javac -cp .;commons-io-2.4.jar AgeFileFilterTest.java
with commons-io-2.4.jar in the same folder as AgeFileFilterTest.java
I was getting error:
import org.apache.*;
^
AgeFileFilterTest.java:24: error: cannot find symbol
displayFiles(directory, new AgeFileFilter(cutoffDate));
^
It was puzzling becuase it seemed all was in place; the jar was in the folder, defined in the classpath, and upon jar content inspection I could see what was being referenced- using 7zip I opened the jar file and could see:
commons-io-2.4.jar\org\apache\commons\io\filefilter\AbstractFileFilter.class
I then read in some post "you do not import the class" which got me to think about the import syntax...
I changed it from:
import org.apache.*;
changing it to:
import org.apache.commons.io.filefilter.*;
and wala compile error gone using: javac -cp .;commons-io-2.4.jar AgeFileFilterTest.java
and program worked using
java -cp .;commons-io-2.4.jar AgeFileFilterTest
Upvotes: 2
Reputation: 68715
Putting the jar in the same folder or package does not add it to the class path. You need to mention the path of the jar in your class path while running your java program. Here is the syntax for that:
To compile:
javac -classpath .;yourjar.jar src/your/package/*.java
To run
java -classpath .;yourjar.jar src/your/package/yourprogrammeclassname
Upvotes: 12