2

I am trying to package a simple JRuby script into a jar file. The script uses Rubeus::Swing and runs correctly when executed with the JRuby interpreter.

require 'rubygems'
require 'rubeus'

class Example01
  extend Rubeus::Swing
  def show
    JFrame.new("Rubeus Swing Example 01") do |frame|
      frame.visible = true
    end
  end
end
Example01.new.show

Once I package the script into a JAR with warble, when I execute:

java -jar jtest.jar

... the JFrame window shows up and instantly closes.

There is no indication of errors of any kind.

Does anyone know why this happens?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
aladac
  • 53
  • 8

2 Answers2

7

Warbler calls System.exit() after your main script exits. This causes the Swing EventThread to exit, closing your app.

https://github.com/jruby/warbler/blob/master/ext/JarMain.java#L131

I worked around this problem by joining with the event thread at the bottom of my start script like so:

event_thread = nil
SwingUtilities.invokeAndWait { event_thread = java.lang.Thread.currentThread }
event_thread.join

Hacky, but it works.

Ben Rady
  • 136
  • 1
  • A more complete sample is here for Ben's Excellent fix. [Example Gist](https://gist.github.com/patrickjonesdotca/5075104) –  Mar 03 '13 at 07:15
1

Just set the appropriate flag:

System.setProperty("warbler.skip_system_exit","true");