How to tell JRuby about reloading / updating a Java class?

I am using JRuby for Java. Using JRebel, I can automatically reload modified Java classes in the JRuby JVM without rebooting. When I add a new Java method, JRebel automatically reloads the class. My problem is that I cannot name this new method directly. Can I ask JRuby to update the method cache for the newly reloaded Java class? My only workaround is to call a new method using java_send.

Example:

Step 1. Start the irb session and java_import Java class (say, Person).

Step 2. Add the getName method to Person and compile.

Step 3. Create an instance of Person (p = Person.new). JRebel will show that it has reloaded the java class.

Step 4. Calling p.get_name results in a NoMethodError, but p.java_send ('getName') calls the newly implemented getName method

+4
source share
2 answers

I found a way to run JRuby with JRebel!

The trick is to run JRuby with a Nailgun server that uses JRebel as follows:

jruby --ng-server -J-javaagent:/Applications/ZeroTurnaround/JRebel/jrebel.jar -J-noverify 

Now the rails application can be launched using Nailgun:

 jruby --ng -S rails server 

If rails uses Java classes somewhere and it can find the correct rebel.xml, JRebel will record the changes and you will no longer need to restart the rails.

 $CLASSPATH << "#{RAILS_ROOT}/java/target/classes" 

JRuby / JRebel still needs additional work, since JRuby does not pick up changes to class declarations, but only the contents of known methods.

+3
source

Did you manage to pass the -javaagent parameter so that it is recognized by the JIRB and runs the jrebel agent?

  jruby -J-noverify -J-javaagent: /path/to/jrebel.jar -S jirb

I tried this but can't see it working, also with java_send

0
source

Source: https://habr.com/ru/post/1312231/


All Articles