How to hot deploy sources with gradle into tomcat7?

2.8k views Asked by At

Does anybody know a gradle 'hot deployment' plugin (or middleware as shell script) which is coping files from source folder directly into project folder at tomcat's webapps directory (not embedded server like gretty or gradle tomcat plugin; version7, environment independent)?

At the end I want to realize a smart dev workflow to (re-, un-) deploy a java web application during code crafting. I'm searching for something like grunt watch tasks.

Scenario: Java web application with self contained, executable jar file at WEB-INF/lib folder.

  • register watcher tasks on top on gradle task
  • java source is changed
  • tomcat stopped
  • remove jar file at WEB-INF/lib folder
  • deploy jar file
  • copy jar into WEB-INF/lib folder (delete all log files)
  • start tomcat

Restart tomcat is not needed if static sources are changed (e.g. JSP, JS, ect.).

Solution

I thought about our working practices at the office. My colleagues and I, we program on Windows machines and we use a key map configuration in IDEA to start and stop our local installed Tomcat.

The easiest way for me is to define a user related CATALINA_HOME system environment variable which references the path to Tomcat server.

CATALINA_HOME = C:\Program Files\apache-tomcat-7.0.56

I define a deploy task which copy compiled war file into webapps folder ((re)start Tomcat manually via IEDA).

task deploy(type: Copy) {
    def WEBAPPS_HOME = System.getenv()['CATALINA_HOME'] + '/webapps'
    from 'build/libs/app.war' into WEBAPPS_HOME
    dependsOn war
}

Nobody need to change Tomcat path inside build.gradle file or there is no additional user.config file which is ignored by git. But I don't like manual Tomcat handling and it is unusual to work with environment variables on Mac's.

So, I decide to search an embedded Tomcat server as Gradle cargo plugin for local development. It is recommanded from Benjamin Muschko (Gradleware Engineer) at How to use local tomcat?... and he describe the differences between Cargo or Tomcat plugin....

Setup of this plugin is quite easy. I don't need to explain.

Nobody need to install there own Tomcat and everybody work with same version server.

For our nigthly build I use the power of Gradle wrapper as Jenkins task configuration. I execute a wintods batch command.

cd "%WORKSPACE%\app"
gradlew.bat clean build
1

There are 1 answers

1
Dave On

I use Jenkins to manage deployments for our applications.

There are a number of plugins which help with such tasks along with having the ability to write your own scripts.

Jenkins is highly configurable so you are able to adapt it to your own needs.

Jenkins URL