javaintellij-ideagradleclasspathrt.jar

Why is rt.jar not part of the class path system property?


I use the system property java.class.path to find all jars and directories that belong to the classpath. At first sigth this seems to work great. But on closer inspection I found that when I execute my program with gradle there is no rt.jar in this classpath. When executed from IntelliJ IDEA ´rt.jar´ is part of that class.

Why do the classpaths between IntelliJ and Gradle differ in this way?

Just to be clear: All the classes contained in rt.jar get loaded just fine, it is just the property that is confusing me.


Solution

  • rt.jar doesn't need to be in the classpath, since it is already in the bootclasspath. It is safe to remove it from your classpath.

    You can refer to this Oracle doc: http://docs.oracle.com/javase/8/docs/technotes/tools/findingclasses.html

    How the Java Launcher Finds Bootstrap Classes

    Bootstrap classes are the classes that implement the Java 2 Platform. Bootstrap classes are in the rt.jar and several other jar files in the jre/lib directory. These archives are specified by the value of the bootstrap class path which is stored in the sun.boot.class.path system property. This system property is for reference only, and should not be directly modified.

    It is very unlikely that you will need to redefine the bootstrap class path. The nonstandard option, -Xbootclasspath, allows you to do so in those rare cicrcumstances in which it is necessary to use a different set of core classes.