How to get boot class path in JDK 9 or later

6k Views Asked by At

I have a classloader application that reads the system property sun.boot.class.path

But I've found in the JDK 9's release note that this property has been removed.

 System.getProperty("sun.boot.class.path"); // In JDK 9/10 this returns null 

But I still want to retrieve this property value in JDK 10. How can it be done?

I'm expecting a value like the following:

/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/resources.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jsse.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jce.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/charsets.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jfr.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/classes

FYI:

I don't want use the -Xbootclasspath option. Just need the path value.

1

There are 1 best solutions below

3
kadar On

Delete the boot. it should work like that :

System.getProperty("java.class.path")

To understand more :

The System class has two methods used to read system properties: getProperty and getProperties.

The System class has two different versions of getProperty. Both retrieve the value of the property named in the argument list. The simpler of the two getProperty methods takes a single argument, a property key For example, to get the value of path.separator, use the following statement:

System.getProperty("path.separator"); The getProperty method returns a string containing the value of the property. If the property does not exist, this version of getProperty returns null.

The other version of getProperty requires two String arguments: the first argument is the key to look up and the second argument is a default value to return if the key cannot be found or if it has no value. For example, the following invocation of getProperty looks up the System property called subliminal.message. This is not a valid system property, so instead of returning null, this method returns the default value provided as a second argument: "Buy StayPuft Marshmallows!"

System.getProperty("subliminal.message", "Buy StayPuft Marshmallows!"); The last method provided by the System class to access property values is the getProperties method, which returns a Properties object. This object contains a complete set of system property definitions.