When exactly Java looks for dependencies of a Jar file at Run Time?
At the very beginning of running it?
When it tries to Initialize a Class which has some dependency?
Or any other time?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The Java Language Specification, §12.3 says (my emphasis):
Now, the specification says that a JVM can do a range of things, but clearly, any given JVM does do one particular thing. Marko’s answer says that "all class files in the classpath may be loaded even before the
mainmethod starts executing", and he’s right, but the fact is that no JVM actually does that.I believe that what actually happens in the Sun JVM is that things are loaded as late as possible. Whenever a class is initialized, then any classes it refers to need to be loaded and verified, but they don’t need to be initialized until they themselves are actually used. I appreciate that this is not a very detailed or authoritative answer.