JRuby脚本与Rubeus和Swing退出一次打包成jar使用warble [英] JRuby script with Rubeus and Swing exiting once packaged into jar using warble
问题描述
我试图将一个简单的JRuby脚本打包到一个jar文件中。
脚本使用 Rubeus :: Swing ,并在使用JRuby解释器执行时正确运行。
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
当我用 warble
将脚本打包到JAR中时,执行:
Once I package the script into a JAR with warble
, when I execute:
java -jar jtest.jar
。 .. JFrame窗口显示并立即关闭。
... the JFrame window shows up and instantly closes.
没有任何类型的错误指示。
There is no indication of errors of any kind.
有人知道为什么会发生这种情况吗?
Does anyone know why this happens?
推荐答案
.exit()在主脚本退出后。这会导致Swing EventThread退出,关闭您的应用程序。
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,但它工作。
Hacky, but it works.
这篇关于JRuby脚本与Rubeus和Swing退出一次打包成jar使用warble的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!