JRebel Resource Center

Maven plugin configuration

JRebel maven plugin will automatically create the rebel.xml for your maven projects. The plugin is available from Maven Central repository.

STEP 1: Automatically generate rebel.xml at each build

Add this to your pom.xml:

<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>

[Optional] STEP 2: Generate virtual classpath configuration

Run mvn jrebel:generate. This will generate rebel.xml in target/classes. You can set the location of generated rebel.xml with -Drebel.xml.dir=some_directory, by default rebel.xml is generated in your project output directory.
Adding -Drebel.generate.show=true will print out generated rebel.xml at info level, so you can immediately see what was generated.

[Optional] STEP 3: Use relative paths in generated configuration

By default generated rebel.xml contains absolute paths. So if you use artifacts built by someone else then the rebel configuration packaged inside artifacts may not work for you. To use relative paths you will need to set two things:

  1. The root directory of your maven projects
  2. The relative path from current module to root directory

If 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 pom.xml:

<configuration>
  <!--
    root is 2 directoris away from jar/war modules
  -->
  <relativePath>../../</relativePath>
  <!--
    use a system property for specifing root directory (note the double $)
    start your application with -Drebel.root=c:/projects/
  -->
  <rootPath>$${rebel.root}</rootPath>
</configuration>

Now you will have c:/projects/my-maven-project1/my-jar1/target/classes as ${rebel.root}/my-maven-project1/my-jar1/target/classes in the rebel.xml.

[Optional] STEP 4: Additional configuration

Have a look at rebel.xml at JRebel configuration page.
A sample Maven plugin configuration with comments follows:

<plugin>
  <groupId>org.zeroturnaround</groupId>
  <artifactId>jrebel-maven-plugin</artifactId>
  <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 absoulte 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>
 
  </configuration>
</plugin>

STEP 5: Let us know

Post your comments and suggestions to our forum.