How to kill JVM loaded by Ruby-Java Bridge (Rjb)

392 Views Asked by At
  • I am using Rjb to access an external Java library in Ruby.
  • The Java class I am using can only be configured once per JVM run.
  • In my tests, I need to test the Java class against different configuration settings.
  • Therefore, I am looking for a way to "reset" Rjb, i.e. kill the JVM and start a new one.

Is this possible? How?

2

There are 2 best solutions below

1
On BEST ANSWER

I used VisualVM to detect the presence or absence of the JVM, and found that Rjb::unload works. However, when I try reloading the JVM, it fails. Here's the irb session that shows this:

➜  ~  irb --prompt simple
>> require 'rjb'
=> true
>> Rjb::load
=> nil
>> Rjb::unload
=> 0
>> Rjb::load
RuntimeError: can't create Java VM
    from (irb):4:in `load'
    from (irb):4
    from /Users/kbennett/.rvm/rubies/ruby-1.9.3-p392/bin/irb:16:in `<main>'
>> 

-- Keith


http://about.me/keithrbennett

1
On

(Disclaimer: When I used rjb, it never had rock solid stability.)

I set a Ruby instance variable to be the instance of a Java class. When I was done, I set the Ruby instance variable to nil.