Servlet Reloading in Java Web Server


I am using Java Web Server - NT 4.0, i have placed my servlet under the
Web server root/classes directory, but when ever i do changes in my servlet, it is not reloading automatically, but if i try to stop and start the web server service, it is ok.

How do i achieve the servlet reloading without restarting the web server.
Any way ?, please help me!

G Ramesh
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


Hi Ramesh,

 It is better to put servlets not reloadable.

Automatical reloading will cause some side effects in some cases.

Cureently what u are doing is correct.

BTW  can u grade my applet answer??
>>>>>but when ever i do changes in my servlet, it is not reloading automatically, but if i try to stop and start the web server service, it is ok.

If you want the servlet to be reloaded every time you change the class files ,place it in

server_root/servlets directory.

What you r doing right now is highly desirable ,dont change the configuration when u r ready to deploy the servlet ,pasting from one of the PAQ's over here

'ClassCastException  in the servlet' 

this problem has been detailed in the Jason Hunter's excellent book see Pgs
55 & Pgs 339

I will type some text from there.Pg 55

Servlet reloading may appear to be a simple feature ,but its actually quite a hack. ClassLoader objects are designed to load a class just once.

To get around this limitation and load servlets again & again ,servers use Custom class loaders that load servlets from the default servlets directory.
This explains why the servlet classes are found in the server_root/servlets ,even though that directory doesnt appear in the server's classpath.

Servlet reloading is NOT performed for classes found in the server's classpath(such as server_root/classes) coz those classes are loaded by the core,primordial class loader. These classes are loaded once and retained in memory even when their class files changes.

It is generally good to put servlet support classes soemwhere in classpath of web server where they dont get reloaded.More explanation .....

This moving of servlets to classpath improves performance a bit,since the server does not need to check the class files timestamp to decide whether to reload the class file.

Pg 339
A server uses a new ClassLoader each time it reloads a servlet. This has the interesting side effect that when the YourServlet class is reloaded ,it is actually a different version of YourServlet than the version used by other classes.Thus although the returned class type is YourServlet and it's being cast to YourServlet ,the cast is between differeing types(from 2 different classloader objects) and the cast HAS to throw the dreaded ClassCastException.

The same type mismatch can occur if the class performing the cast (that is the servlet performing the above code) is reloaded. Why? because the new ClassLoader wont find YourServlet using the primordial Class loader and will load it's own copy of YourServlet.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

Hi Amit:-

Is the book is in readable format on net like you are telling???

I found only the code part in net in

I want the book on online like the real book.

Is it there ??
no it's not,I have the book here at our place ,and I read and typed the above thing myself.

rameshg21Author Commented:

Thanks, i really like the people who spends their time for me!

Thanks a lot to mbormann, and ravindra

G Ramesh
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.