I am using eclipse with tomcat. I am building and managing a web application. My problem is that it needs to restart the server again and again for a simple change and that's quite annoying. So is there any method to auto deploy the war by tomcat, so that changes can be affected without server restart. I want to change the jsps as well as java classes also. Please help me out. I have read some queries in this website, but couldn't understand it. Please give step by step methods.
-
It may help http://stackoverflow.com/questions/1873920/restart-tomcat-when-a-class-file-is-changed – Shriram Aug 01 '15 at 09:04
-
@RomanC - If we want to change a little in the java classes, then to reflect it in your web app you need to restart the server. – Arnab Dhar Aug 01 '15 at 11:01
-
@ArnabDhar No, you are absolutely incorrect, changed classes could be reloaded hot (reload content and resources) and cold (redeploy) without server restart, all this things should be handled by IDE, but I'm not sure if any commercial version of eclipse is doing that. – Roman C Aug 01 '15 at 11:09
1 Answers
I thought that eclipse did this for you, but I may be wrong. I personally tackled this issue in my build system using a different route because I don't use eclipse, but you could also use it with eclipse.
I use Gradle which allows me to write tasks to move files. You could also do this with Ant. To deploy to tomcat you have to drop a .war file into the webapps folder of your tomcat server (This will be different on everyones machine). Tomcat then takes this .war file opens it and creates a directory by the same name, in that folder, this is what is used to display your files.
To push your edits to tomcat without needing a restart, you need to move your .war to the webapps folder and erase the directory tomcat made for you. This still creates a problem where it takes a second to unzip your war, so another approach is to just move the new classes and web files directly into the folder that tomcat made for you by unzipping the .war. I call this hot swapping. Below is an example of a task I wrote in gradle. You could download Gradle Buildship for eclipse and do the same.
def tomcat = '/usr/local/Cellar/tomcat/8.0.24/libexec/webapps'
def pNmae = 'myApp'
// Below is a task to move your war to webapps
// deploy your application to your machine.
task devDeploy(type: Copy){
description 'Deploys a war of your plugin to tomcat for local development.'
from archives
into tomcat
include '**/*.war'
}
// Below is code to move the files directly into the directory tomcat makes
// for the quicker viewing of changes in a running tomcat instance
task loadClasses(type: Copy){
description 'Hot swap your tomcat class files directly'
from 'build/classes/main'
into tomcat + '/' + pName + '/WEB-INF/classes'
}
task loadWebFiles(type: Copy){
description 'Load web files into tomcat directly'
from 'src/main/webapp'
into tomcat + "/" + pName
}
task hotswap << {
description 'Swap files in a running instace of tomcat'
tasks.loadWebFiles.execute()
tasks.loadClasses.execute()
}
This solution only really works for you if you want to use gradle, or write a script to do the same thing. I hope at least this helps you understand what is needed to render changes in your app without restarting on tomcat.

- 2,013
- 17
- 26
-
I am using maven with my project. Could you help me with the context of maven?? @Pumphouse – Arnab Dhar Aug 01 '15 at 18:15