Application configuration (rebel.xml)

JRebel maps your project workspace directly to a running application. It watches for changes you make to classes and resources, and then intelligently reflects them in your application. In order for it to happen, JRebel needs to know where your classes and resources are. JRebel uses the rebel.xml configuration file to map your deployed project back to your workspace. This is obligatory when you deploy your app as a WAR or EAR. You will need to have one rebel.xml file per module. This includes both web and EJB modules.

JRebel has dedicated plugins for Maven and Gradle.

Note

The rebel.xml configuration file should end up in your WEB-INF/classes directory in case of a web module. In case of an EJB module or a JAR library, it should be in the root of the archive. Place it in the root of a source or resource folder in your project (the same place where .properties files are located) and make sure it is copied to the target directory.


Configuring JARs

JARs are usually not deployed on their own, but as a part of an application (e.g. WEB-INF/lib in WARs or EJB modules in EARs). You might still want to update their code on the fly. Let’s assume that we have a module my-business-module.jar deployed in WEB-INF/lib. You can propagate the changes from your workspace by adding the following rebel.xml to the root of the JAR file:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com"
             xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
  <classpath>
    <dir name="c:\myWorkspace\myBusinessModule\target\classes"/>
  </classpath>
</application>

This will mount classes and resources in c:\myWorkspace\myBusinessModule\target\classes before the classes and resources in the JAR file. Changes to those classes and resources will propagate to the application.


Configuring WARs

In case of a web application you have web application resources, like JSPs, HTML files, graphic files and so on in addition to the classpath. To configure a web application deployed as a WAR file we create a rebel.xml file in the WEB-INF/classes directory:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com"
             xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">

  <classpath>
    <dir name="c:\myWorkspace\myWar\target\classes"/>
  </classpath>

  <web>
    <link target="/">
      <dir name="c:\myWorkspace\myWar\src\main\webapp"/>
    </link>
    <link target="/jsps/">
      <dir name="c:\myWorkspace\myWar\src\main\jsps"/>
    </link>
  </web>

</application>

This will mount classes and resources in c:\myWorkspace\myWar\target\classes to the application classpath before the deployed classes and resources. This means that those classes and resources will override the ones in WEB-INF/classes and WEB-INF/lib/\*.jar. Changes to those classes and resources will propagate to the application.

This will also map the web resources in c:\myWorkspace\myWar\src\main\webapp directory to the root (“/”) of the web application context and the web resources in c:\myWorkspace\myWar\src\main\jsps directory under the /jsps/ URI of the web application context. You may map several directories to one context target if necessary.


Configuring EARs

To configure an EAR you need to create a separate rebel.xml file for each EAR internal module, meaning WARs and JARs. Web modules should be configured the same as individually deployed WARs, EJB modules should be configured same as JARs. If your container supports APP-INF/classes you may also add a rebel.xml to that folder. Then mount classes and resources that belong to the EAR as a whole.


Using relative paths

Using absolute paths in rebel.xml might be a bad idea as you’d like to share it with other team members. Luckily JRebel will expand expressions like ${myproject.root} in rebel.xml to a property that you provide. You can set this as a Java system property, e.g. -Dmyproject.root=c:/projects/.


Tips and tricks

  • You are not limited to mounting directories to classpath. You can also mount JARs with <jar>.
  • If you need to mount a bunch of directories or JARs at once you can use <dirset> or <jarset> that accepts Ant-style patterns to specify the specific directories.
  • You can use Ant FileSet-style include and exclude directives in <dir> and <jar> entries.

Configuration file reference

A special configuration file - rebel.xml - must be used for web applications that use packaged deployment (i.e. WARs, JARs and EARs). Instead of the WAR/JAR/EAR file deployed all resources will be picked up from the locations provided in rebel.xml. Also these directories and archives will be monitored for changes.

The rebel.xml must be placed in the WEB-INF/classes directory of the deployed WAR file, in a root directory of a JAR file or in the root of EJB JAR modules. A rebel.xml file should be provided per each module in the application that you want to change on the fly.

The contents of rebel.xml are defined by the schema at http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd. This link contains a full example at the end of this file.

JRebel will expand expressions like "${myProject.root}" in rebel.xml to a system property that you can pass to the application container as -DmyProject.root=c:/myWorkspace/myProject. This allows using a single configuration for everyone and then customizing it when starting the server.


<application>

Top level tag that defines the configuration with classpath, WEB and WAR tags.

<?xml version="1.0" encoding="ISO-8859-1"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com"
             xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
  ...
</application>

<classpath>

Defines the mounted classpath of the application with nested dir, dirset, jar and jarset elements. The fallback attribute checks whether classes and resources are also found from the original application classpath (e.g. WEB-INF/classes, WEB-INF/lib/*.jar, JAR root, etc.).

Attribute Description Required
fallback

Values: all, none and default (default).

  • If set to all, classes and resources will always be found from both the original and mounted classpath. This mode may cause some resources to appear double in the application.
  • If set to none, classes and resources will only be found from the mounted classpath. This mode requires all classes and resources (including e.g. those in WEB-INF/lib/*.jar) to be fully mounted.
  • If set to default, classes and resources will be found from both original and mounted classpath, but resources present in both will be filtered out. This mode implies that classes and resources in the path that contains rebel.xml are fully present in the mounted classpath (e.g. all classes and resources in WEB-INF/classes should be mounted if rebel.xml is present).
No
<?xml version="1.0" encoding="ISO-8859-1"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com"
             xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
  <classpath>
    ...
  </classpath>
</application>

<dir>

Directory on the filesystem that is added to classpath or link. Nested include/exclude tags can be used to limit the files included from the specified directory.

Attribute Description Required
name A full path to a directory on the filesystem. Yes
include Specifies a pattern that directs which resources will be included from the parent. No
exclude Specifies a pattern that directs which resources will be excluded from the parent. No
<?xml version="1.0" encoding="ISO-8859-1"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com"
             xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
  <classpath>
     <!--
      Add a directory with class files to the classpath. The classes
      can also be excluded or included based on patterns.
     -->
     <dir name="c:\projects\myProject\classes\">
       <!-- Including everything from com/yourapp/package1-->
       <include name="com/yourapp/package1/**"/>
       <!-- Exclude the unimportant subpackage of package1-->
       <exclude name="com/yourapp/package1/unimportant/**"/>
     </dir>
  </classpath>
</application>

<dirset>

Defines multiple subdirectories of a directory that can be added to classpath. Nested include/exclude tags can be used to limit the subdirectories included from the specified directory.

Attribute Description Required
dir The parent directory from which subdirectories are found. By default all will be added. Yes
include Specifies a pattern that directs which resources will be included from the parent. No
exclude Specifies a pattern that directs which resources will be excluded from the parent. No
<?xml version="1.0" encoding="ISO-8859-1"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com"
             xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
  <classpath>
    <!--
      DIRSET enables you to add multiple directories to the classpath
      without specifying them one-by-one. For example if there are multiple
      MAVEN modules with a similar folder structure. The following configuration
      will include all modules from the directory of "c:\projects\project1Root\
      that adhere to the pattern "**\build\classes".
    -->
    <dirset dir="c:\projects\project1Root\">
      <include name="**\build\classes"/>
    </dirset>
  </classpath>
</application>

<jar>

Defines a JAR file that is added to classpath or link. Nested include/exclude tags can be used to limit the resources included from the specified JAR.

Attribute Description Required
name Full path to a JAR file that is added to the CLASSPATH. Yes
include Specifies a pattern that directs which resources will be included from the parent. No
exclude Specifies a pattern that directs which resources will be excluded from the parent. No
<?xml version="1.0" encoding="ISO-8859-1"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com"
             xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
  <classpath>
    <!--
      Adds a JAR file to the classpath. The classes from the
      JAR archive can also be excluded or included based on patterns.
    -->
    <jar name="c:\projects\myProject\3rdpartyLibs\myLibrary.jar">
      <!-- Including everything from com/yourapp/package1-->
      <include name="com/yourapp/package1/**"/>
      <!-- Exclude the unimportant subpackage of package1-->
      <exclude name="com/yourapp/package1/unimportant/**"/>
    </jar>
  </classpath>
</application>

<jarset>

Defines multiple JAR files to be added to classpath. Nested include/exclude tags can be used to limit the JARS included from the specified directory.

Attribute Description Required
dir JAR files from this directory on the filesystem are added to the CLASSPATH. Yes
include Specifies a pattern that directs which resources will be included from the parent. No
exclude Specifies a pattern that directs which resources will be excluded from the parent. No
<?xml version="1.0" encoding="ISO-8859-1"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com"
             xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
  <classpath>
    <!--
      JARSET enables you to add multiple JAR files to the classpath without
      specifying them one-by-one. The following example includes JAR files
      from the app/3rd-party-lib directory that don't match the pattern apache*.jar.
    -->
    <jarset dir="app/3rd-party-lib">
      <exclude name="apache*.jar"/>
    </jarset>
  </classpath>
</application>

<war>

Overrides the WAR file deployed to the container with a exploded directory or a WAR file on the filesystem. Needs to have either dir or file attribute.

Attribute Description Required
dir Path to an exploded WAR directory on the filesystem. Resources and class files will be loaded from this directory. Yes/No
file Path to a WAR archive on the filesystem. Resources and class files will be loaded from this file. Yes/No
<?xml version="1.0" encoding="ISO-8859-1"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com"
             xsi:schemaLocation="http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
  <!--
    WAR tag with FILE attribute specifies the location of the WAR file.
    The contents of this WAR file will have higher priority as compared
    to the web application deployed. All resources in this file will be
    available in the web application just as they would be in the
    deployed WAR file.
  -->
  <war file="c:\projects\myProject\dist\myProject.war" />
</application>
<?xml version="1.0" encoding="ISO-8859-1"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com"
             xsi:schemaLocation="http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
  <!--
    WAR tag with DIR attribute specifies the location of the exploded
    directory. The contents of this directory will have higher priority
    as compared to the web application deployed to the container. All
    resources in this folder will be available in the web application
    just as they would be in the deployed web application.
  -->
  <war dir="c:\projects\myProject\dist\war" />
</application>

<web>

Defines separate locations for static resources that can be referenced from the web application. With nested link tags it is possible to map different resources from the filesystem to the web context.

<?xml version="1.0" encoding="ISO-8859-1"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com"
             xsi:schemaLocation="http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
  <!--
    WEB tag defines separate locations for static resources that can be referenced from
    the web application. Directories containing jsp, css, html, gif etc. files. These
    directories can be mapped to arbitrary locations for the web application.
  -->
  <web>
    ...
  </web>
</application>

<include>

This element is used to filter resources in dir, dirset, jar and jarset elements. Resources named by this element will be included in the result. This element uses Ant-style patterns.

Attribute Description Required
name Name that will be filtered, can contain wildcards. See example for more information. Yes
<dirset dir="c:\projects\project1Root\">
  <include name="**\build\classes"/>
</dirset>
...
<jarset dir="app/3rd-party-lib">
  <exclude name="apache*.jar"/>
</jarset>
...
<jar name="c:\projects\myProject\3rdpartyLibs\myLibrary.jar">
  <!-- Include all of package1-->
  <include name="com/yourapp/package1/**"/>
  <!-- Except for internal subpackage-->
  <exclude name="com/yourapp/package1/internal/**"/>
</jar>

<exclude>

This element is used to filter resources in dir, dirset, jar and jarset elements. Resources named by this element will be excluded from the result. This element uses Ant-style patterns.

Attribute Description Required
name Name that will be filtered, can contain wildcards. See example from include tag for more information. Yes
<dirset dir="c:\projects\project1Root\">
  <include name="**\build\classes"/>
</dirset>
...
<jarset dir="app/3rd-party-lib">
  <exclude name="apache*.jar"/>
</jarset>
...
<jar name="c:\projects\myProject\3rdpartyLibs\myLibrary.jar">
  <!-- Include all of package1-->
  <include name="com/yourapp/package1/**"/>
  <!-- Except for internal subpackage-->
  <exclude name="com/yourapp/package1/internal/**"/>
</jar>

Sample configuration

The following file can be copied to your project. The relevant sections can be deleted or customized.

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
  <classpath>
    <dir name="C:/Users/user/workspace/spring-petclinic/target/classes">
    </dir>
  </classpath>
</application>