Hi guys, I am using Tomcat 5.5 and I want to enable servlet reloading when class files for servlets have changed. How do I do this in Tomcat 5.5?
I am working from a book that suggests adding this piece of XML:
But it does not say where abouts to add it. I read somewhere that I should add it as a child of my Service element. So Server/Service/DefaultContext. But I read another page here that seems to suggest that this setup will not work for Tomcat 5.5. It suggests the following:
a) Create a StandardContext
b) Load the context.xml
c) Load web.xml with the same procedure at b)
app /webapps/app/WEB-INF/web.xml or at war app.war!/WEB-INF/web.xml
I've found another reference that seems to support the idea of adding this DefaultContext element as a child of my Host element. It says the following:
The only change that needs to be made to server.xml is to allow Tomcat to automatically reload a servlet if its .class file has been modified. Open server.xml in a text editor and look for the closing tag. Add this code BEFORE the </host> tag.
Hmmm I just tested Tomcat using the HelloWorld example that ships with it. It seems adding the DefaultContext element to the Hosts element in the server.xml does not cause the new class files to be picked up.
What I did was:
1) Add the DefaultContext element to the Hosts element in the server.xml
2) Start up Tomcat.
3) Loaded the Hello World servlet http://localhost/servlets-examples/servlet/HelloWorldExample (this worked)
4) Change the source \apache-tomcat-5.5.34\webapps\servlets-examples\WEB-INF\classes\HelloWorldExample.java
5) Compiled the source
6) Waited about 30seconds. Refreshed my browser. No change was shown!!!
I was then able to see my change that I made to the Servlet. So now I am back to my original question - how do I get Tomcat 5.5 to automatically pick up the new class file once it has been modified? I want to do this across the entire Tomcat server rather than setting for each Web App.
Well, with a bit of better Googling I came across the correct instructions. Now my Tomcat is picking up servlets that have been modified. Result!!!
I am following the book called Core Servlets and JavaServer Pages. The instructions in the book for setting up Tomcat are the same as the ones on the associated website located here. But it turns out these guys have created updated instructions for setting up Tomcat 5.5 which are located here. I like it !