Search code examples
javaservletsclassloader

Which class would load first when Web application starts?


I have a web application and two class files,

First class is MyClass.class which is inside the abc.jar file (WEB-INF/lib/abc.jar) and Second class is YourClass.class which is inside classes folder (WEB-INF/classes/ YourClass.class).

My question is which class would load first when the Application starts? And Why ?


Solution

  • In my experience you can't predict the order in which the classes are loaded by the JVM.

    Once I made a test runner (kinda Maven's Surefire) and with the same JVM and OS it loaded classes in different order when run in different machines. The lesson learnt:

    You shouldn't build your applications to depend on class loading order