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.
The moose likes Tomcat and the fly likes reflect on web-application changes in servlets class file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "reflect on web-application changes in servlets class file " Watch "reflect on web-application changes in servlets class file " New topic
Author

reflect on web-application changes in servlets class file

sajid dayer
Greenhorn

Joined: Mar 07, 2015
Posts: 17
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 63548
    
  72

Not with Tomcat as far as I am aware.

[Asking smart questions] [About Bear] [Books by Bear]
sajid dayer
Greenhorn

Joined: Mar 07, 2015
Posts: 17
but some one told me using root.xml its happen
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 63548
    
  72

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.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17278
    
  28

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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 63548
    
  72

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.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17278
    
  28

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: reflect on web-application changes in servlets class file
 
It's not a secret anymore!