Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enable Servlet Reloading in Tomcat 5.5

 
Sean Keane
Ranch Hand
Posts: 582
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sean Keane
Ranch Hand
Posts: 582
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 582
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 582
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 582
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic