You are here

Hot reloading in IntelliJ

Hot reloading is the ability to modify your application's code, and view the changes without having to restart 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.
This assumes you have a simple AMP archetype project imported into IntelliJ (as done in the previous tutorial).
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 Java code, although hot reloading of JavaScript and FreeMarker code also works.
  1. If not already running, run your AMP project in IntelliJ as detailed in the previous tutorial. Make sure that Alfresco has fully started.
  2. In the IntelliJ Project Explorer expand src/test/java to locate the source file.
  3. Load it into the editor by double-clicking it.
  4. Now set up a Run Configuration to run JUnit tests. From the main menu select Run > Edit Configurations.
  5. In the Run/Debug Configurations dialog, click '+' to create a new configuration. Select JUnit from the list of available configuration types.
  6. Set the Name field of the configuration to "DemoComponentTest".
  7. In the Class field, select the class (if not already present).
  8. Set the VM options field as follows:

    -ea -Xms1024m -Xmx4096m -XX:PermSize=1024m -javaagent:/Users/tbedford/Downloads/springloaded-1.2.0.RELEASE.jar -noverify                        
    Attention: Change the path to Spring Loaded to reflect your system.
  9. Set the project Working directory to the root of the project (if not already present).
  10. Click OK.
  11. Now run the test by selecting Run > Run 'Demo Component Test' from the main menu.

    The test will run, and three tests will pass.

  12. Now, in, modify one of the tests so that it will fail. For example, you could change the line assertEquals(7, childNodeCount); to assertEquals(8, childNodeCount);
  13. Now run the test again by right-clicking the file in Project Explorer and selecting Run 'DemoComponentTest' .

    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.

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

    It will immediately show green, with all tests passing. 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.