Using Redeploy, Reload, Hot swap To Speed Up MES Development

  1. In case to redeploy our MES app you should do below steps:
    1. go to server.xml in your tomcat/conf directory
    2. set unpackWARs to true and autoDeploy to true in Host tag or remove these attributes
      <Host name="localhost" appBase="webapps"
      unpackWARs="true" autoDeploy="true"
      xmlValidation="false" xmlNamespaceAware="false">
    3. restart tomcat
    4. build new war in mes-application directory
    5. copy war generated in target directory to tomcat/webapps AS ROOT.war
    6. wait some time and check logs if tomcat redeploy ROOT.war
    7. the application is first deleted entirely from its deployed directory, and then re-deployed onto the server from your appBase directory
  2. In case to reload our MES app plugins (it's classes) you should do below steps:

    1. go to context.xml in your tomcat/conf directory
    2. set reloadable="true" in Context tag

      <Context reloadable="true">
    3. restart tomcat
    4. build new jar in your plugin directory
    5. copy jar generated in target directory to tomcat/webapps/ROOT/WEB-INF/lib/
    6. wait some time and check logs if tomcat reload your jar and it's classes
    7.  Reload an application means to call a method of the StandardContext class called StandardContext.reload() on a given Context.  This method creates a new classloader and new servlets, drops all references to the old servlets, and then calls the Servlet.init() method on the servlet, which brings the servlet to an initialized state, triggering a reload of all classes and libraries by the new classloader.  


  3. Hot swap - If you are willing to make use of HotSwap feature you have to be able to debug MES in your IDE first. Please note that HotSwap is limited to method body changes only (unless you use http://hotswapagent.org/ tool). The steps described below assume that you use IntelliJ IDEA.

    1. Run Tomcat in debug mode, by executing:
      catalina.sh jpda start

      The above command will make Tomcat to listen on port 8000 for you to attach with debugger.

    2. Configure your IDE in order to connect to remote Tomcat instance. Transport: socket; Debugger mode: Attach; Host: localhost; Port: 8000.

    3. Make further configuration of HotSwap feature under Build, Execution, Deployment > Debugger > HotSwap. This step is optional, however I suggest to disable Build project before reloading classes, as we don't want to build the whole project, but rather modified classes only.

    4. Run debug session.

    5. Select Build > Recompile 'ChangedClassName.java'.

    6. After compilation is done you should be asked to reload modified classes (when Reload classes after compilation is set to ask). If everything goes right, you should be notified about successful class reloading. Enjoy