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 脚本退出
基础教程推荐
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- Maven:无效的目标版本:10 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- JPA惰性列表上的流 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- 将 double 转换为 Int,向下舍入 2022-01-01
