WebSphere Liberty enables you to re-deploy your application without restarting the application server each time. JRebel, from ZeroTurnaround, adds to this by enabling you to instantly reload your code without needing to redeploy or restart the application each time either. It seamlessly integrates with Liberty and the WebSphere Developer Tools.

This quick tutorial will take you through downloading Liberty, setting up a server, installing JRebel and then showing it in action. The following steps give an overview of how to install Liberty profile but if you need more details, take a look at the Getting Started articles and videos.

  1. Install the WebSphere Developer Tools for the version of Eclipse that you are using:


    EMP-Liberty

  2. Now that the tools are downloaded and installed, you need to install the Liberty profile runtime. Select File > New > Other…, then select the New Server wizard. Choose the Liberty profile and click Next.


    NewLibertyServer

  3. Click on the download and install option.


    Profile

  4. Choose the Liberty profile V8.5.5.x Runtime repository site and click Next, then additionally mark the CDI sample for installation. We will use this project to see JRebel in action.


    download

    When the installation completes, you will see the server in your environment:


    ServerRunning

  5. We also want to see the source code so that we can modify it and see JRebel instantly reload our changes. We can use the standard Import WAR wizard to do this. The CDI sample application will be in the dropins directory of the server you just installed; e.g. <root path to installed server>usrserverscdiSampledropinscdiApp.war:


    ImportCDI

    Then you just need to link up your source with the application deployed in the Liberty server. Just drag and drop the cdiApp project in the Enterprise Explorer view on to the Liberty server that you created.

    Start the server and enter the URL for the application http://localhost:9100/cdiApp/sample.jsp in your browser (just to check that things are working OK!).


    CDI-Original

  6. Now you’re ready to install JRebel from the Eclipse Market Place. Before you do this, though, you may need to get a trial JRebel licence if you do not already have one.

    When you access the Eclipse Marketplace, search for JRebel. Click Install and follow the instructions:


    EMP-JRebel

  7. When Eclipse restarts, you will be prompted to configure JRebel:


    JR-Config-Prompt

    Click on the Open Config Center log, then use the Activate / Update License option to activate JRebel:


    JR-Activate-Licence

  8. Enable JRebel for your Liberty server. This turns off automatic publishing on Liberty, but that’s fine as JRebel is now going to handle that for us:


    JR-Enabled-Liberty

  9. The final step is to enable JRebel for our project:


    JR-Enable-CDI

    In your server console you will now see that JRebel is now integrated with your Liberty server:


    JRebel-Log

  10. Now, let’s alter the message which is printed out from the injected bean. Open the InjectedBean class and change the message. In this case by adding the text “Updated by Jrebel”.

    @RequestScoped
    public class InjectedBean {
    	
        /**
         * @return a customized message for this bean
         */
        public String getValue() {
            return "Congratulations! You successfully used CDI to inject a bean at the request scope! updated by JRebel";
        }
        
    }
    

    When you refresh in the browser then you’ll see a log message stating that the changed class has been reloaded:


    JR-Log-Update

    Your browser will also show the updated message:


    CDI-Rebel

  11. Finally, let’s do something that JVMs find hard (if not impossible) to do and that is add another method into a class that has already been loaded – in this case our injected bean:

        /**
         * @return a customized message for this bean
         */
        public String getValue() {
            return "Congratulations! You successfully used CDI to inject a bean at the request scope! " + getJRebelText();
        }
        
        private String getJRebelText() { 
        	return "Updated by JRebel (new method)"; 
        } 
    

    This change is then instantly reloaded by JRebel, and refreshing your browser now shows the updated method being invoked:


    CDI-Rebel-NewMethod

And that’s it! JRebel will now take care of updating the server with changes that you make to your code. You can find out more information about JRebel on the ZeroTurnaround web site.

Join The Discussion

Your email address will not be published. Required fields are marked *