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 脚本退出
基础教程推荐
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
