It’s fairly straightforward to install JRebel to run on a local instance of Tomcat, here is one way of installing it on Tomcat running in a docker container instead. This article assumes a basic knowledge of using docker.
For this particular example I’m using:
- the Eclipse IDE installation of JRebel
- the ‘official’ Tomcat 8 image from the Docker hub
Install JRebel in the IDE
I’m using the Eclipse IDE, but there are instructions on the ZeroTurnaround website on using a different IDE or for installing it standalone.
1. For Eclipse, follow these instructions just to install and activate JRebel for the IDE:
https://zeroturnaround.com/software/jrebel/quickstart/eclipse/#!/server-configuration
2. We need the JRebel agent (jrebel.jar) to install into Tomcat.
You can either get this from the JRebel plugin you have just installed into Eclipse (look for the section titled ‘Where do I find jrebel.jar?’);
http://zeroturnaround.com/software/jrebel/learn/remoting/eclipse/
OR you can get it from an archive
https://zeroturnaround.com/software/jrebel/download/prev-releases/
(Note that for Tomcat 8, please use the legacy version of jrebel.jar which is found in the lib sub-directory of the zip archive.)
Install JRebel in the Application Server
1. Get the base Tomcat docker image from the docker hub.
docker pull tomcat:xxx
Here xxx is the specific version of Tomcat you want to use as the base image, e.g. 8.0.23-jre7, 8-jre8, etc. You can find the list in the Tomcat docker repository:
2. Since we are using docker to run the application server, then we will need to run JRebel in remote mode. There are generic instructions on JRebel remoting, which we can adapt to do it in a docker environment. So what we want to do is to create a custom docker image, based on the Tomcat image, which incorporates the JRebel configuration.
2.1 Create an empty directory and copy the JRebel agent jrebel.jar to it.
2.2 Create a Dockerfile to build your custom Tomcat image, for example:
Note that for simplicity, I have just added the JRebel agent to the directory /jrebel. You can use a different directory, as long as the -javaagent configuration can find it.
Also you can take this opportunity to do further customizations on the Tomcat server, e.g. if you want to add your list of users, then copy the your version of tomcat-users.xml to the Tomcat config directory by adding this line to the Dockerfile:
ADD tomcat-users.xml /usr/local/tomcat/conf/
2.3 Build and run the customized Tomcat server (using your own repository name, image name and container name to replace the values in this example).
docker build -t your_repository/tomcat-jrebel . docker run -i -t -d --name mytomcat -p 8080:8080 your_repository/tomcat-jrebel
We can verify that the JRebel configuration has been included in Tomcat by checking the startup logs.
docker logs mytomcat
We should be able to see the JRebel version and licensing information.
2015-05-22 10:38:40 JRebel: ############################################################# 2015-05-22 10:38:40 JRebel: 2015-05-22 10:38:40 JRebel: JRebel Legacy Agent 6.2.0 (201505201206) 2015-05-22 10:38:40 JRebel: (c) Copyright ZeroTurnaround AS, Estonia, Tartu. 2015-05-22 10:38:40 JRebel: 2015-05-22 10:38:40 JRebel: Over the last 1 days JRebel prevented 2015-05-22 10:38:40 JRebel: at least 0 redeploys/restarts saving you about 0 hours. 2015-05-22 10:38:40 JRebel: 2015-05-22 10:38:40 JRebel: Server is running with JRebel Remoting. 2015-05-22 10:38:40 JRebel: 2015-05-22 10:38:40 JRebel: 2015-05-22 10:38:40 JRebel: #############################################################
Tip: Build Your Own
Of course you can combine these 2 steps for creating a custom image into 1, by creating your own Tomcat image from scratch instead of using the ‘official’ Tomcat image as a base.
Configure the IDE
Finally we need to configure Eclipse to work with the Tomcat server that we have running in docker. You can do that by following these instructions.
This is a brief summary of the steps:
- In Eclipse, right-click on your project, select JRebel -> Add JRebel Nature
- Right-click on your project again, select JRebel -> Enable remote server support
- Right-click on your project again, select JRebel -> Advanced Properties
- In the dialog that pops up, click on “Edit” button next to the “Deployment URLs” text box
- Click on “Add” and enter the URL of the application, it will be something like “http://your_docker_host:8080/app_name”
- Click on “Continue”, “Apply”, and then “OK”.
Once the app is deployed, any changes you make in the IDE should now be reflected in the server running in the docker container.
No restarts, no redeploys, just code.