This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Tomcat and the fly likes Web applications only deployed after restart of tomcat 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 "Web applications only deployed after restart of tomcat" Watch "Web applications only deployed after restart of tomcat" New topic
Author

Web applications only deployed after restart of tomcat

Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi guys,

I've configured Tomcat (5.5 on Gentoo) to allow per user web applications in ~user/public_html with the following additional listener in the server.xml config:

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

<Listener className="org.apache.catalina.startup.UserConfig"
directoryName="public_html"
userClass="org.apache.catalina.startup.PasswdUserDatabase"/>
.....
</Host>

So far everything is working fine except applications aren't auto deployed or undeployed by tomcat! I've tried this with unpacked web applications and .WAR files but no applications are deployed or undeployed without restarting Tomcat.

After all information i found on the web i'm unsure if auto deployment in userdirs is even possible. Does anyone know how to fix this problem so i don't have to restart the server everytime i make changes to my applications under ~user/public_html/... ?

Thanks a lot!

Marco
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I don't see the autoDeploy attribute in the Host entry that you posted.
Did you try setting that?

From: http://tomcat.apache.org/tomcat-5.5-doc/config/host.html

autoDeploy

This flag value indicates if new web applications, dropped in to the appBase directory while Tomcat is running, should be automatically deployed. The flag's value defaults to true. See Automatic Application Deployment for more information.





Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Thanks for this hint Ben, but i actually can see the autoDeploy attribute in my post


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


So there has to be another reason. By the way auto deploying works fine for my "normal" apps but just not for those in my user dirs!
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Doh,

I shouldn't post to this forum before drinking my caffine.
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

After some testing i've gathered additional information what causes web applications files in a user dir to be automatically reloaded/refreshed.

When Tomcat starts up a context is created for every user directory which has a web directory in it like public_html for example.
With the admin application included in Tomcat i'm able to set the attribute "reloadable" to "true" for such a context and then everything works as expected. Every change in the user dir is noticed by tomcat and immediately visible in my browser.

But this solution doesn't work really well. First i have to set reloadable to true for every user context by hand. Furthermore changing this setting with the admin application leads to a static <Context> entry in my server.xml and i have to restart Tomcat at least once after changing this setting for all contexts.

I think what would really help me would be a possibility to tell Tomcat to create these contexts by itself with the reloadable attribute already set to true.

Any suggestions? Some other ideas? Thanks in advance!

Marco
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12753
    
    5
When Tomcat starts up a context is created for every user directory which has a web directory in it like public_html for example.


I believe the requirement is that Tomcat finds a WEB-INF containing a valid web.xml, otherwise it ignores the directory.

Are you really trying to let users run arbitrary code and serve arbitrary html on your server? Sounds like a recipe for disaster to me.

Bill
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Sorry Bill, but it also doesn't work with a correct WEB-INF/ and web.xml!

And of course you're right, i wouldn't want everybody to be able to execute arbitrary code on my server!

In fact it's for an exam where every student has to develop a web application in his personal home directory. And at the moment nobody didn't get it to work with auto deployment, so the only solution is a cronjob which restarts Tomcat every few minutes. Of course this is very annoying because you have to wait some time until you can test the result. And i simply can't believe that there isn't a better solution to this problem ;)

Marco
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410



Are you setting up a separate host for each student?
If so shouldn't the appBase point to their home directory?
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

No, it's just one host container with the config i posted above! And this host uses the "webapps" directory for all "ordinary" web applications.

The per user directories are only managed by the <Listener> element within this <Host> element:


<Listener className="org.apache.catalina.startup.UserConfig"
directoryName="public_html"
userClass="org.apache.catalina.startup.PasswdUserDatabase"/>


This is already working correctly! It get's the home directories from /etc/passwd on UNIX/Linux systems and searches for a "public_html" directory within these home directories.

Just auto deployment respectivly noticing changes in this directories doens't work automatically without restarting Tomcat.
An alternative way to achieve this is to just reload the context for a user directory from the manager application. But normal users don't have access to the manager app and in spite of everything i can't believe that it is not possible to achieve what i want without manual user intervention.

Is it really that unusual what i want to do? I didn't find useful information both by crawling the web and the Tomcat docs. In fact it seems i'm the only one using this setup

I'd still be very thankful for any kind of help!

Marco
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12753
    
    5
Is it really that unusual what i want to do?


Yes! Running web apps for weeks without change is probably the norm.

I recently tackled the problem of adding new HttpServlet handlers without restarting Tomcat - after a long strange trip through ClassLoaders I got something working but it may not be enough for what you are trying to do because it did not provide much for static content.

It is basically a REST style web service handler using a custom ClassLoader that can load a class implementing doGet and doPost as required. You have to use reflection to actually execute the methods.

Bill
 
wood burning stoves
 
subject: Web applications only deployed after restart of tomcat
 
Similar Threads
Security Contraints setup..
JNDI in Servlets
Session ID
server.xml quirk with startup servlet
HTTP to HTTPS not redirecting