Tomcat Clean Batch File

We use tomcat a lot at work and sometimes you will deploy the same application tens of times in a single day.

Before deploying a new version of the application I’m about to work on, I like to:

  • Clean out the logs directory – much handier to see what’s going on with a fresh set of logs
  • Clean out the work directory – it’s amazing how many times you can deploy a new version and it doesn’t seem to be acting any differently than before and it’s because of the copy in the work directory…!
  • Remove the artefact + exploded folder from the webapps directory.

Although those three tasks wouldn’t seem to take time, they’re very boring repetitive tasks that if could be done with one button would make deployment of a new version a lot quicker…

So a number of months ago at home, I decided to make the following script to give me a one button way of running all of those tasks.  This script is a Windows bat file, but could easily be converted to shell, etc. It can also be extended to stop the tomcat instance, deploy the new war file after cleaning the directories and then starting up the tomcat container.

Simply place in the root directory of tomcat, e.g. C:/Program Files/Apache/tomcat-7.0.52/clean.bat.  It will delete all wars and associated war exploded directories, so if you want one specific war not deleting, you’ll need to modify the script!

DOH… My custom url checker won’t allow me to post the code, so here’s a snapshot…

cleanbat