Search code examples
rubyjrubyrjb

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


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


Solution

  • 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