File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Enable Servlet Reloading in Tomcat 5.5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Enable Servlet Reloading in Tomcat 5.5" Watch "Enable Servlet Reloading in Tomcat 5.5" New topic
Author

Enable Servlet Reloading in Tomcat 5.5

Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

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
global /conf/context.xml
host /conf/<engine>/<host>/context.xml.default
app /conf/<engine>/<host>/app.xml
c) Load web.xml with the same procedure at b)
global /conf/web.xml
host /conf/<engine>/<host>/web.xml.default
app /webapps/app/WEB-INF/web.xml or at war app.war!/WEB-INF/web.xml

Now I am pretty confused. Any help appreciated.

Cheers, Sean.


SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

The code example on this page here has the following:
<Engine name="Catalina" defaultHost="localhost">

<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>

<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">

<DefaultContext reloadable="true">
</DefaultContext>

<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->

</Host>
</Engine>


So maybe I should just place it in this location too? i.e. Server/Service/Engine/Host/DefaultContext

The poster in the link above seems to be using Tomcat 6. Wondering would this still apply to 5.5?

I just want the easiest and simplest way of setting this up. Any ideas?
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

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.

<DefaultContext reloadable="true" />
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

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!!!

So then I did this:
7) Stopped Tomcat.
8) Started Tomcat.
9) Loaded the Hello World servlet http://localhost/servlets-examples/servlet/HelloWorldExample (this worked)

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.

Any ideas?
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

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 !

Glad we had this conversation.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Enable Servlet Reloading in Tomcat 5.5
 
Similar Threads
What is Tomcat virtual host, What is different from the Apache Tomcat?
Help Tomcat5.5.7: Error in catalina
message-resources reload
Cannot create JDBC driver of class 'oracle.jdbc.OracleDriver'for connect URL 'jdbc:oracle:oci:@mydbs
adding a Datasource to tomcat jndi