tags:

views:

412

answers:

5

Hello to all,

I've made a web application using Java, Struts and running over Apache Server and Tomcat. It would be very useful to be able to restart the application from the web. I don't want to restart Tomcat, only this wbapp, the same way as Tomcat Manager does it.

Do you know how can I do it? If not, any way to simulate that behaviour (reload config.properties, make Hibernate init process, etc)?

Thank you a lot.

John Pollancrot

+1  A: 

You may find this link to be useful.

McWafflestix
Thanks McWafflestix.This is the Tomcat Manager. I use it, but you must know login and password and it is'n always installed. I need, if possible, something using only that web application.Thanks again.
No worries; since tomcat is open source, have you tried looking at what the Tomcat Manager does, and extracting that bit of functionality?
McWafflestix
Good idea! I'll try it later. Thanks!
+2  A: 

I took a quick look at the source code for the Tomcat Manager. It looks like there's a class that's part of the Tomcat source called "Container Servlet". From the javadocs:

A ContainerServlet is a servlet that has access to Catalina internal functionality, and is loaded from the Catalina class loader instead of the web application class loader.

A ContainerServlet automatically gets passed a wrapper that can be used to get the Context and Deployer -- and the Deployer has helpful methods such as start(String contextPath) and stop(String contextPath) that will do what you want.

So, what I think you would need to do is write your own servlet that inherits from ContainerServlet, and configure Tomcat to load your servlet using the Catalina class loader (look at how the Manager is configured to see how). Note that this is probably not going to be an option for you in a hosted environment.

Then your servlet could have, say, a button you press to reload the application. I recommend putting password-protection of some kind in front of that. :)

JacobM
A: 

Tomcat Manager offers an http interface to start/stop an application and other tasks. There are Ant tasks that you can use to easily access these operations.

kgiannakakis
A: 

Good ideas here, I'll try it.

Thanks!

John Pollancrot

A: 

Just hit the URLs

http://<username>:<password>@<hostname>:<port>/manager/stop?path=/<context path>

to stop and

http://<username>:<password>@<hostname>:<port>/manager/start?path=/<context path>

to start. That simulates you using the manager application.

NeilInglis