I'm trying to use Apache's PDFBox library. For some reason, javac is unable to load pdfbox-2.0.28.jar. When I run any of the following commands in Bash:
javac -cp "pdfbox-2.0.28.jar" MyPdf.java
javac -cp ".:pdfbox-2.0.28.jar" MyPdf.java
javac -cp "pdfbox-2.0.28.jar:." MyPdf.java
javac -sourcepath "pdfbox-2.0.28.jar" MyPdf.java
I get this error:
MyPdf.java:1: error: package org.apache.pdfbox does not exist
import org.apache.pdfbox.*;
^
1 error
I know that the jar file is not corrupted because I can extract its contents without a problem. The class files within that jar files also exist. The MyPdf.java is a simplistic java code with following content:
import org.apache.pdfbox.*;
public class MyPdf {
public static void main (String... args) {}
}
My directory tree:
pdf
├── MyPdf.java
├── pdfbox-2.0.28.jar
└── sample.pdf
File list of pdfbox-2.0.28.jar file:
$ unzip -l pdfbox-2.0.28.jar
Archive: pdfbox-2.0.28.jar
Length Date Time Name
--------- ---------- ----- ----
18161 2023-04-10 10:05 META-INF/MANIFEST.MF
0 2023-04-10 12:05 META-INF/
1655 2023-04-10 10:04 META-INF/DEPENDENCIES
23477 2023-04-10 10:04 META-INF/LICENSE
638 2023-04-10 10:04 META-INF/NOTICE
0 2023-04-10 12:05 META-INF/maven/
0 2023-04-10 12:05 META-INF/maven/org.apache.pdfbox/
0 2023-04-10 12:05 META-INF/maven/org.apache.pdfbox/pdfbox/
134 2023-04-10 10:05 META-INF/maven/org.apache.pdfbox/pdfbox/pom.properties
43315 2023-04-10 10:04 META-INF/maven/org.apache.pdfbox/pdfbox/pom.xml
0 2023-04-10 12:05 org/
0 2023-04-10 12:05 org/apache/
0 2023-04-10 12:05 org/apache/pdfbox/
0 2023-04-10 12:05 org/apache/pdfbox/contentstream/
431 2023-04-10 10:04 org/apache/pdfbox/contentstream/PDContentStream.class
7327 2023-04-10 10:04 org/apache/pdfbox/contentstream/PDFGraphicsStreamEngine.class
25077 2023-04-10 10:04 org/apache/pdfbox/contentstream/PDFStreamEngine.class
0 2023-04-10 12:05 org/apache/pdfbox/contentstream/operator/
... snipped ...
1514 2023-04-10 10:04 org/apache/pdfbox/util/filetypedetector/ByteTrie$ByteTrieNode.class
2585 2023-04-10 10:04 org/apache/pdfbox/util/filetypedetector/ByteTrie.class
1880 2023-04-10 10:04 org/apache/pdfbox/util/filetypedetector/FileType.class
3308 2023-04-10 10:04 org/apache/pdfbox/util/filetypedetector/FileTypeDetector.class
--------- -------
5603142 879 files
I looked at some of the search results from this web search query, including the one here but none of them solved my problem.
How do I figure out what I'm doing wrong? It is not the first time for me to load a library using classpath but I cannot get this thing to work.