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.
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 ;-)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With