0

I have the following project structure

project-root
--core
---build.gradle
---project.gradle
--web
---build.gradle
---project.gradle

I configured jRebel to run with gradle, so I can start my embedded tomcat 8 with the command gradle tomcatRun

This shows log-output of jrebel and my application starts on the embedded server, but there is no hot deployment when i change java files.

With the IntelliJ JRebel Plugin I created the rebel.xml files for each of the project project-root, core and web. Also I added a rebel.xml inside the web project in the folder web/build/classes/main as described here

Normally jrebel should show at startup that its wachting some folders, but this is not the case on my site, so i guess there is something wrong with my configuration

here the rebel.xml files

project-root (Path c:/project-root/rebel.xml)

     <?xml xsd....">
        <classpath>
            <dir name="c:/project-root/out/production/classes">
            </dir>
        </classpath>
     </application>

core (Path c:/project-root/core/src/main/resources/rebel.xml)

    <?xml version="1.0" encoding="UTF-8"?>
    <application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_1.xsd">
        <classpath>
            <dir name="c:/project-root/core/out/production/resources">
            </dir>
            <dir name="c:/project-root/core/out/production/classes">
            </dir>
        </classpath>
    </application>

web (Path c:/project-root/web/src/main/resources/rebel.xml)

    <?xml version="1.0" encoding="UTF-8"?>
    <application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_1.xsd">
    <classpath>
        <dir name="c:/project-root/web/out/production/classes">
        </dir>
    </classpath>
    </application>

web (Path c:/project-root/web/build/classes/main/rebel.xml)

    <?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:/project-root/web/build/classes/main">
        </dir>
    </classpath>
    <web>
        <link target="/">
            <dir name="c:/project-root/web/src/main/webapp">
            </dir>
        </link>
    </web>
    </application>

To attach jrebel to my gradle i did the following batch calls before starting gradle tomcatRun

set REBEL_HOME=C:\Users\myuser\.IdeaIC2017.3\config\plugins\jr-ide-idea\lib\jrebel6
set JAVA_OPTS="-agentpath:%REBEL_HOME%\lib\jrebel64.dll"

then calling gradlew tomcatRun starts the tomcat and jrebel

    gradlew tomcatRun
    2018-01-09 10:24:09 JRebel:  Starting logging to file: C:\Users\myuser\.jrebel\jrebel.log
    2018-01-09 10:24:09 JRebel:
    2018-01-09 10:24:09 JRebel:  #############################################################
    2018-01-09 10:24:09 JRebel:
    2018-01-09 10:24:09 JRebel:  JRebel Agent 7.1.3 (201711301108)
    2018-01-09 10:24:09 JRebel:  (c) Copyright ZeroTurnaround AS, Estonia, Tartu.
    2018-01-09 10:24:09 JRebel:
    2018-01-09 10:24:09 JRebel:  Over the last 2 days JRebel prevented
    2018-01-09 10:24:09 JRebel:  at least 0 redeploys/restarts saving you about 0 hours.

But when I change some source files, nothing is detected by jrebel, also when i manually called gradlew compileJava

Al Phaba
  • 6,545
  • 12
  • 51
  • 83

2 Answers2

2

I think that the problem is that JRebel is not attached to the actual process running the embedded Tomcat server. Instead, it gets attached to the Gradle's wrapper process. Try attaching JRebel's JVM argument via the org.gradle.jvmargs option instead.

gradle tomcatRun -Dorg.gradle.jvmargs="-agentpath:/path/to/jrebel/lib/libjrebel64.so"

Additionally, since tomcatRun task makes use of exploded deployment, rebel.xml files will not be necessary. This is because the build output directory is the same as the deployment directory and the changes made in that directory are automatically picked up by JRebel and reloaded.

Make sure to also compile the changes that you made using the gradle compileJava command to do so.

I tried it out personally and it seems to work well. Although it does not output the JRebel banner to the console output, it does let you know when a class file was reloaded.

Tiit
  • 185
  • 2
  • 8
  • I does not work on my side, i have added some additional info to my post. It seems ok, tomcat starts with jrebel but jrebel does no recognize any change. Can you share a sample project? Maybe with a working project i can see my error – Al Phaba Jan 09 '18 at 09:35
  • Thanks, I will check and give you feedback – Al Phaba Jan 10 '18 at 00:57
  • Strange, thanks to your answer, I was able to see that when tomcat starts it shows that jrebel is watching the classes folder. But when i do changes of one of my classes and compiled them, it does not effect anything. Although i could see in the jrebel.log that a change event for my class happened. I changed only a log-output but the entry in the logfile was unchanged. Everything seem so work, jrebel start with the tomcat, jrebel shows event changes when I compile my classes but does not change the log output of my file. I working with threads in my project, may this be a problem? – Al Phaba Jan 11 '18 at 00:33
  • @AlPhaba It seems to be some kind of configuration issue. Please reproduce this issue, then zip and send the `jrebel.log` file from your `~/.jrebel/` directory to support@zeroturnaround.com with a brief issue description and a reference to this SO article. – Tiit Jan 11 '18 at 06:43
0

While the answer by Tiit is correct, I would like to add that when using Gretty, you need to specify the -agentpath:/path/to/jrebel/lib/libjrebel64.so argument in your build.gradle file like so:

gretty {
  . . .
  jvmArgs = [
    '-agentpath:/path/to/jrebel/lib/libjrebel64.so'
  ]
}

otherwise, by using -Dorg.gradle.jvmargs option, JRebel agent seems to attach to a wrong process when using Gretty launcher.