Reputation: 2338
I know that we use classpath to add third party jars when we start any java process. Does anybody have any resource or information about how the JVM reads or what the JVM does with jars specified in the classpath?
I am just curious how the JVM exactly handles the classpath.
Thanks.
Upvotes: 2
Views: 245
Reputation:
The classpath is read linearly so that when a class is requested Java finds the first instance of it on it's classpath. That being said, there are actually three classpath levels in play when you launch Java. The first one is the bootstrap classpath which contains the java core jars (java.lang, etc.). The second one is the extension classpath that contains any jars found in the extention (ext) directory of the java installation. The third is the user specified classpath of the running program. These classpaths will always be read linearly in order starting with the bootstrap, then the extension, and finally the user specified classpath. This is what prevents someone from overriding the java.lang classes in a normal program. The first class found that matches always wins even if there is another match later in the classpath.
Upvotes: 2