You can use the -verbose
option of the java
command and search for the fully qualified name of a specific class.
$ java -verbose -jar MyProgram.jar | grep "java.lang.String"
[Loaded java.lang.String from /Library/Java/…/Contents/Home/jre/lib/rt.jar]
[Loaded java.lang.StringBuffer from /Library/Java/…/Contents/Home/jre/lib/rt.jar]
…
Addendum: I want to check the class availability for an environment.
If you are running from the java
command line, either the paths specified in the -classpath
option or the CLASSPATH
environment variable will be searched. If you are running from a JAR, the manifest's Class-Path
attribute, for example, supplants these settings.
If you are trying to find a required JAR that may not be accessible in these ways, you'll have to search the file system. I use a combination of find
, jar
and grep
, typically focussing on paths defined in system properties such as java.endorsed.dirs
and java.ext.dirs
; several related approaches are shown here.