Keith John Hutchison Keith John Hutchison - 1 year ago 91
Java Question

How to specify a wildcard path for jar libraries for a java command line application?

I'm writing a command line utility to extract Adobe Form Data from PDF's

This command line fails.

java -classpath jars/*.jar:. extractpdfformdata.ExtractPDFFormData --pdf csmu-asfm.pdf

where as this works.

java -classpath jars/commons-cli-1.3.1.jar:. extractpdfformdata.ExtractPDFFormData --pdf csmu-asfm.pdf

What is the correct way to pass in wildcard paths for jar libraries to java?

ck1 ck1
Answer Source

The correct way is to use simply jars/*. Classpath wildcards in the Oracle JRE represent a list of .jar files, and not part of the file name. Here's a quote from the documentation:

Class path entries can contain the base name wildcard character (*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example, the class path entry mydir/* specifies all JAR files in the directory named mydir. A class path entry consisting of * expands to a list of all the jar files in the current directory. Files are considered regardless of whether they are hidden (have names beginning with '.').

Reference: Class Path Wild Cards at

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download