Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Locate Java standard library

What is the best way to locate the jar containing core Java classes such as java.lang.Object? I have been using JAVA_HOME, but it turns out that that only works if the JDK is installed. How can I just find the standard library location that would be used if java were run from the commandline?

Also, I need to do this from a Python script, so please don't respond with Java libraries.

like image 219
Antimony Avatar asked Nov 24 '12 22:11

Antimony


2 Answers

When you launch java from Oracle's JVM, it sets sun.boot.class.path property to point to rt.jar, which normally contains all the java.lang stuff.

What you could do is to launch a simple Java program which retrieves System.getProperty("sun.boot.class.path") and gets where this file is supposed to be. Read more on this here.

Above should work if your environment is correct (JAVA_HOME is set, etc.). Otherwise, I'm afraid you have chicken and egg problem ;-)

like image 96
mindas Avatar answered Sep 30 '22 13:09

mindas


Since there are no explicit restrictions on placing internal classes, then you should try handle all the possible (or as much as possible) places.

First of all, you should definitely look for java in PATH. Unfortunately, it will fail sometimes, for instance, you can often find java.exe in C:\Windows\System32. Fortunately, in case of Windows you can use registry to get a list of installed JREs.

If you have found some jars which might contain basic classes, you can use zip or jar to check that java/lang/Object.class is there.

like image 39
tcb Avatar answered Sep 30 '22 13:09

tcb