Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 546
Isabel Jinson Avatar asked Mar 10 '26 15:03

Isabel Jinson


1 Answers

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

like image 158
victor hugo Avatar answered Mar 12 '26 05:03

victor hugo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!