Book Image

Instant JRebel

By : Jonathan Lermitage
Book Image

Instant JRebel

By: Jonathan Lermitage

Overview of this book

JRebel is a JVM plugin that lets Java developers update code instantly and see their changes reflected in their application under development without restarting the application server. JRebel is a plugin for anything that is in Java and is also IDE neutral. If you want to update your code instantly without compiling and deploying the code repeatedly, this book is for you.This book will focus on the most important development steps and will also help you save time which is otherwise spent on compilation and deployment of code. You will learn how to use JRebel with the most popular IDEs and Java servers and how to accelerate the development of your current and future Java SE and Java EE projects.This book shows you how to install JRebel, configure your favourite IDE and Java server for JRebel, and start using it on your projects.With this book, you will learn how to get a free license for JRebel and how to integrate JRebel with most Java servers and development environments. To finish, you will see how to work with desktop and web projects and how to utilize JRebel to dramatically accelerate their development.
Table of Contents (7 chapters)

Introducing JRebel (Must know)


Before trying to use JRebel, let's have a look at the existing features offered by modern IDEs such as NetBeans. They are already able to accelerate your developments. We will see later why JRebel is a better choice.

Also, many developers associate JRebel with Java EE applications only, but keep in mind it works with any Java SE application too, including GUI software!

How to do it...

Modern IDEs offer some ways to accelerate your developments and deployments. We will show one of them, called Deploy on Save on NetBeans using the following steps:

  1. Understand what a class loader is. Download and install the latest version of Oracle JDK7 from http://www.oracle.com/technetwork/java/javase/downloads/index.html (on Ubuntu, you may use the sudo apt-get install openjdk-7-jdk command to install JDK7) and NetBeans IDE from https://netbeans.org/downloads/. Please choose the Java EE or All bundle of NetBeans.

  2. Download and install the latest binary version of Apache Tomcat server from http://tomcat.apache.org/download-70.cgi. You should use the ZIP version. It is easier to register in NetBeans than the Windows Service Installer version.

  3. Register the Tomcat server in NetBeans by launching NetBeans and going to the Services tab. Right-click on the Servers node, then click on the Add Server... register, then choose Apache Tomcat from the server list to register the Tomcat server.

    Registering Tomcat into NetBeans

  4. Create a simple Java web project. You can do it by navigating to File | New Project | Java Web | Web Application. Remember to choose Tomcat as the server. It will create a simple web application with a HelloWorld JSP file. Now, create a simple servlet by navigating to File | New File | Web | Servlet. See the differences when Compile on Save is enabled and disabled. You can activate this feature present in the Projects Properties panel by checking the Deploy on Save checkbox.

    The Deploy on Save feature

How it works...

A web application is a good example to explain the principle of the Deploy on Save feature of NetBeans.

You probably already know that you can modify and save a JSP file; the server will automatically reload it without restarting or redeploying anything. Meanwhile, servlets are Java classes and won't be reloaded so easily. Without the help from an IDE, you would normally need to rebuild your application and redeploy it.

The Deploy on Save feature is designed to redeploy your servlets automatically. You only have to save the edited file and you'll see the changes immediately.

So, is there anything else to improve the development process?

Unfortunately, the Deploy on Save system is limited it consumes time and can't update the entire web applications or configuration files. This is exactly why JRebel is useful. JRebel is comparable to the best Deploy on Save systems, but it also offers many advanced capabilities. It offers two types of improvements:

  • Changes to Class structure: This targets Java SE applications (such as desktop applications) and Java EE applications.

  • JRebel is able to apply changes to many Java elements. The following are the details:

    • It applies changes to method bodies

    • It adds/removes methods

    • It adds/removes constructors

    • It adds/removes fields

    • It adds/removes annotations

    • It adds/removes classes

    • It applies changes to static field values

    • It adds/removes enumeration values

    • It applies changes to interfaces

  • Instant Builds: It targets Java EE applications only. JRebel is able to apply changes to Java EE elements. The following are the details:

    • It skips builds for WAR directories

    • It skips builds for WAR/EAR class updates

    • It skips builds for WAR/EAR resource updates

    • It maps multiple source dirs to one WAR/EAR target dir

    • It maps classes and resources with include/exclude patterns

    • It maps multiple source dirs with Ant-style patterns

    • It uses system properties to make mapping machine-independent

JRebel is entirely transparent; simply save the modifications to observe changes in the live application. It works with any kind of Java application.