You are here

Hot reloading in Eclipse

Hot reloading is the ability to modify your application's code, and view the changes without having to reload Alfresco or Tomcat. This allows for significant savings in development time that would be wasted restarting Alfresco or Tomcat. Hot reloading is the key to enabling RAD and TDD.
It will be helpful if you have an AMP archetype up and running.
In this tutorial you will see how changes to your code can be carried out without having to restart your application. This tutorial demonstrates hot reloading of JavaScript, FreeMarker and Java code.
  1. The Alfresco AMP project has a sample JavaScript-based web script included in the project. You can run this by pointing your web browser at http://localhost:8080/alfresco/service/sample/helloworld. Running this web script (log in as admin, password admin if required) you will see "Message: Hello World!" displayed.
  2. In Eclipse Package Explorer expand src/main/amp/config/alfresco/extension/templates/webscripts to expose the web script files.
  3. Load the file webscript.get.js into the Eclipse editor.
  4. Modify the message string and save the file.
  5. Now switch back to your browser and hit refresh. The new message will be displayed.

    Note that you did not need to refresh web scripts, restart Alfresco or do anything other than reload the web page. This is one example of hot reloading.

  6. Load webscript.get.html.ftl into the editor. Modify the FreeMarker code in some small way.
  7. Save your changes.
  8. Switch back to the browser and reload the web page.

    Your changes should take effect immediately, without having to refresh web scripts or restart Alfresco.

So far we have seen how hot loading applies to JavaScript and FreeMarker code, but the same also applies to Java code.

  1. In the Eclipse Package Explorer expand src/test/java to locate the DemoComponentTest.java file.
  2. Load it into the editor.
  3. In Package Explorer right-click the file DemoComponentTest.java and select Run As > JUnit test.

    The test will run and in the Console will display "SDK Demo AMP class has been loaded". In the JUnit tab the test will show green (passed).

  4. Now modify one of the tests so that it will fail. For example, you could change the line assertEquals(7, childNodeCount); to assertEquals(8, childNodeCount);
  5. Now run the test again by right clicking the file in Package Explorer and selecting Run As > JUnit test.

    Note the test will run again and this time fail. But you did not need to restart Alfresco. This demonstrates hot reloading of Java code.

  6. Change the code back and re-run the test.

    It will immediately show green. The code has re-run without any reloading of Alfresco! This allows for Test Driven Development with very low overhead.

In this tutorial you have seen how to the Alfresco SDK allows you to modify code and run it without needing to restart Alfresco.

Sending feedback to the Alfresco documentation team

You don't appear to have JavaScript enabled in your browser. With JavaScript enabled, you can provide feedback to us using our simple form. Here are some instructions on how to enable JavaScript in your web browser.