This week's giveaway is in the Spring forum. We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line! See this thread for details.
Hi guys
I just want to know how to make automatic reflect on web application if i make changes in my servlets class file .
Because when ever I make changes in servlets class file I have to do server shutdown and startup
Otherwise go to tomcat web application manager
And reload the web-application
Is there another method which automatic do this
I think that there is a setting that allows tomcat to restart the context if it detects a change; but it still has to restart the context as far as I know. It can't just reload the servlet.
Auto-reload is not recommended for production deployments for various reasons.
Since this was a question for reloading in Tomcat, it really should have been made/moved to the Tomcat forum. Every webapp server has different policies on this.
A Tomcat server with default configuration will scan its deployed WARs every few seconds. If it detects a changed resource, it will halt the WAR, redeploy it with the changed resources and restart it.
This is not something to do lightly. You can potentially end up with transactions which started with one set of logic assumptions/security roles but end with another. In addition, not all resources redeploy cleanly. Especially static objects in servlets and anything in the PermGen space (which leaks and runs out of memory, making Tomcat useless).
Tomcat does not take very long to restart. So it's generally better to stop Tomcat, purge its work/temp files, update the app(s), then restart it.
An IDE is no substitute for an Intelligent Developer.
Tim Holloway wrote:Since this was a question for reloading in Tomcat, it really should have been made/moved to the Tomcat forum.
So done.
Tim mentioned replacing a war file, and this is important. In a production deployment you want control over the build process and the contents of the war file. It would be complete chase to try to update individual files or selves in a production application. There would be no control over exactly what is deployed.
Actually, let me clarify. I use the term "WAR" here to mean a Web Application as it appears within the Tomcat server. Thus my "WAR" can either refer to an actual ".war" file, or an "exploded WAR", which is what you get when you unzip a .war file.
Tomcat, by default, will explode .war files that are dropped into the TOMCAT_HOME/webapps directory, then deploy them. It will not delete the original WAR file from the webapps directory, but any further changes will be based on the exploded WAR.
This means that if you update the .war file and drop the updated .war into TOMCAT_HOME/webapps, Tomcat will ignore those changes. It only works with the exploded WAR. Thus you'd have to delete the exploded WAR directory before Tomcat would explode the new WAR (and create a new exploded WAR directory).
Altering files within an exploded WAR can be done but it is perilous. Updating static content, including HTML, CSS and JavaScript is generally OK and will not cause Tomcat to undeploy/redeploy. Updating JSPs will cause the JSPs to recompile. Updating java classes, however, will trigger the full re-deploy with all of the aforementioned dangers.
On my projects, my desktop Tomcat and Eclipse environment are set up so that Tomcat is directly referencing Maven project target classes (Maven builds an exploded WAR and then ZIPs it up to build a WAR file). Thus, if I modify static content, I can do a "mvn war:exploded" goal run and the altered static content (including JSF templates) will be applied to the running webapp. Which is handly, because restarting Tomcat every time I shift a couple of pixels around would be a pain.
However, changes to Java code require me to stop Tomcat, run "mvn compile war:war" and restart Tomcat.