简体   繁体   中英

Java classpath wildcard not working without quotes

I have a folder with lots of jar files and a classpath:

-classpath ./classes:./jogamp-all-platforms/jar/*

But it doesn't find the package. Just to make sure that I have the resource in question I manually find the jar that contains it and change the classpath to:

-classpath ./classes:./jogamp-all-platforms/jar/jogl-all.jar

And now it isn't complaining about not finding a package.

Under Debian I had to put quotations marks just around the wildcard for this to work: "*"

Then the compile command becomes:

javac -cp ~/my\ stuff/Java/"*" test.java

I'm using JDK, JRE 8.

The issue is that * is expanded to all the entries in your directory and the classpath syntax allows directories and jar files separated with : on your platform. * is expanded and will include all the jars in your directory and you will end with something like:

-classpath ./classes:./jogamp-all-platforms/jar/jogl-all.jar another.jar etc.jar

If in your ./jogamp-all-platforms/ directory you have the jogl-all.jar another.jar etc.jar jars.

You can escape the * expansion by the shell using something like:

-classpath './classes:./jogamp-all-platforms/jar/*'

This way your compiler will interpret the * expansion.

I think you need to use ; as path separator after ./classes as below:

 -classpath ./classes;./jogamp-all-platforms/jar/*

Also please note:

Subdirectories are not searched recursively. For example, jogamp-all-platforms/jar/* looks for JAR/Class files only in jogamp-all-platforms/jar, not in jogamp-all-platforms/jar/abcd, jogamp-all-platforms/jar/efc, etc.

By doing -classpath ./classes:./jogamp-all-platforms/jar/* , it looks of all the JARs in jogamp-all-platforms/jar folder only.

For more details, please refer the documentation here- Wildcards in classpath .

The first form will not work. You cannot load jar files with wildcards. The second form should work, unless you're missing dependent classes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM