JRuby script with Rubeus and Swing exiting once packaged into jar using warble(使用 warble 打包到 jar 中后,带有 Rubeus 和 Swing 的 JRuby 脚本退出)
问题描述
我正在尝试将一个简单的 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.
没有任何错误的迹象.
有人知道为什么会这样吗?
Does anyone know why this happens?
推荐答案
Warbler 在你的主脚本退出后调用 System.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.
这篇关于使用 warble 打包到 jar 中后,带有 Rubeus 和 Swing 的 JRuby 脚本退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 warble 打包到 jar 中后,带有 Rubeus 和 Swing 的 JRuby 脚本退出


基础教程推荐
- 验证是否调用了所有 getter 方法 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 大摇大摆的枚举 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 多个组件的复杂布局 2022-01-01