JRebel Maven plugin

The JRebel Maven plugin is designed to generate the rebel.xml configuration file for your projects.

Tip

When using a JRebel IDE plugin, it is recommended to generate rebel.xml using the IDE plugin. Generating rebel.xml using the JRebel Maven plugin is intended for situations when generation using the IDE plugin is not available.


Download

Download the JRebel Maven plugin at GitHub: https://github.com/zeroturnaround/maven-jrebel-plugin. The source is available under Apache License 2.0.


Using the JRebel Maven plugin

In case of Maven projects – especially in case of multi-module projects – it is handy to use JRebel Maven plugin for generating the rebel.xml configuration file(s). Add the following snippet to your parent pom.xml. The rebel.xml configuration file will be generated for each individual sub-module of your Maven project.

<plugin>
  <groupId>org.zeroturnaround</groupId>
  <artifactId>jrebel-maven-plugin</artifactId>
  <version>1.1.7</version>
  <executions>
    <execution>
      <id>generate-rebel-xml</id>
      <phase>process-resources</phase>
      <goals>
        <goal>generate</goal>
      </goals>
    </execution>
  </executions>
</plugin>

This will automatically generate the JRebel configuration file rebel.xml on every build. If you just want to generate the rebel.xml, run:

mvn jrebel:generate

You can specify the target folder with -Drebel.xml.dir=OUTPUT_DIRECTORY parameter (by default OUTPUT_DIRECTORY is target/classes). Adding -Drebel.generate.show=true will print out generated rebel.xml at info level, so you can immediately see what was generated.

By default, the generated rebel.xml contains absolute paths to your workspace. However, if you want to deploy the artifacts for your team to use, you will need to make sure that the paths are relative using a configurable custom property.

Assuming that you have the following project structure in directory c:\\projects\\:

my-maven-project1
  my-jar1
  my-war1

You should add the following configuration to the plugin:

<configuration>
  <!--
    root is 2 directories up from the jar/war modules
  -->
  <relativePath>../../</relativePath>

  <!--
    use a custom property for specifying root directory (note the double $)
    set the property in JRebel configuration or as -Dmyproject.root=c:/projects/
  -->
  <rootPath>$${myproject.root}</rootPath>
</configuration>

Now you have c:/projects/my-maven-project1/my-jar1/target/classes as ${myproject.root}/my-maven-project1/my-jar1/target/classes in rebel.xml. You can set this property as a Java System property (-Dmyproject.root=c:/projects/).

Note

When working with multiple modules in a single project, you can choose to skip generating rebel.xml for desired modules. Simply add the following:

<plugin>
  <groupId>org.zeroturnaround</groupId>
  <artifactId>jrebel-maven-plugin</artifactId>
  <version>1.1.7</version>
  <configuration>
    <skip>true</skip>
  </configuration>
</plugin>

Advanced configuration

<plugin>
  <groupId>org.zeroturnaround</groupId>
  <artifactId>jrebel-maven-plugin</artifactId>
  <version>1.1.7</version>
  <configuration>
    <!--
     If your project uses custom packaging that is not recognized
     set this to jar or war.
     -->
    <packaging>war</packaging>
    <classpath>
      <fallback>default</fallback>
      <resources>
        <resource>
          <!--
            A relative path.
          -->
          <directory>target/special-classes </directory>
          <!--
            You may use includes and excludes as with any other
            resource.
          -->
          <includes>
            <include>com/yourapp/include/package1/**</include>
            <include>com/yourapp/include/package2/**</include>
          </includes>
          <excludes>
            <exclude>com/yourapp/exclude/package1/**</exclude>
            <exclude>com/yourapp/exclude/package2/**</exclude>
          </excludes>
        </resource>
        <resource>
          <!--
            Empty resource element marks default configuration. By
            default it is placed first in generated configuration.
          -->
        </resource>
        <resource>
          <!--
            An absolute path is used here.
           -->
          <jar>c:\projects\myProject\3rdpartyLibs\myLibrary.jar</jar>
        </resource>
        <resource>
          <jarset>app/3rd-party-lib</jarset>
          <excludes>
            <exclude>apache*.jar</exclude>
          </excludes>
        </resource>
        <resource>
          <dirset>c:\projects\project1Root\</dirset>
          <excludes>
            <exclude>**\build\classes</exclude>
          </excludes>
        </resource>
      </resources>
    </classpath>

    <war>
      <path>c:\projects\myProject\dist\myProject.war</path>
    </war>

    <web>
      <resources>
        <resource>
          <target>gfx/</target>
          <directory>c:\projects\myProject\static\gfx
          </directory>
        </resource>
        <resource>
          <!--
            Empty resource element marks default configuration. By
            default it is placed first in generated configuration.
          -->
        </resource>
      </resources>
    </web>


    <!--
      addResourcesDirToRebelXml - default is false
      Required if the resource directories are to be added to rebel.xml
    -->
    <addResourcesDirToRebelXml>true</addResourcesDirToRebelXml>


    <!--
      alwaysGenerate - default is false
      If 'false' - rebel.xml is generated if timestamps of pom.xml and the current rebel.xml file are not equal.
      If 'true' - rebel.xml will always be generated
    -->
    <alwaysGenerate>true</alwaysGenerate>

  </configuration>
</plugin>

You can also leverage build profiles in order to keep the JRebel configuration separate from the main configuration.

<profiles>
  <profile>
    <id>jrebel</id>
    <build>
      <plugins>
        <plugin>
          <groupId>org.zeroturnaround</groupId>
          <artifactId>jrebel-maven-plugin</artifactId>
          <executions>
            <execution>
              <id>generate-rebel-xml</id>
              <phase>process-resources</phase>
              <goals>
                <goal>generate</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </build>
  </profile>
</profiles>

Executing the example above with the command mvn -Pjrebel clean package will trigger JRebel plugin to generate the rebel.xml file.