从 sbt 0.10.1 运行 JavaFx 2.0 beta 应用程序时抛出 InterruptedException
当尝试从 sbt 0.10.1 运行用 Scala 2.8.1 编写的简单 JavaFX 2.0 beta 应用程序时,应用程序窗口关闭后会引发异常:
> run
[info] Running com.tradex.priceviewer.Main
Exception while removing reference: java.lang.InterruptedException
java.lang.InterruptedException
[ at java.lang.Object.wait(Native Method)success
] at java.lang.ref.ReferenceQueue.remove(Unknown Source)Total time: 5 s, completed Aug 5, 2011 1:12:04 PM
at java.lang.ref.ReferenceQueue.remove(Unknown Source)
at com.sun.glass.utils.Disposer.run(Disposer.java:64)>
at java.lang.Thread.run(Unknown Source)
从命令行运行应用程序时,不会引发异常,返回的状态为 0应用程序的代码如下:
class Starter extends Application {
def main(args: Array[String]) {
Application.launch(args)
}
override def start(s: Stage) {
s.setVisible(true)
}
}
object Main {
def main(args: Array[String]) {
val gui = new Starter
gui.main(args)
}
}
抛出异常后,必须退出并再次启动 sbt(重新加载不起作用)。从 Scala 2.8.1 控制台运行相同的应用程序时,第二次运行后会引发以下异常:
scala> m.main(Array(""))
scala> m.main(Array(""))
java.lang.IllegalStateException: Application launch must not be called more than once
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:41)
at javafx.application.Application.launch(Application.java:115)
at com.tradex.priceviewer.Starter.main(Main.scala:19)
at .<init>(<console>:11)
at .<clinit>(<console>)
at RequestResult$.<init>(<console>:9)
at RequestResult$.<clinit>(<console>)
at RequestResult$scala_repl_result(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at scala.tools.nsc.Interpreter$Request$$anonfun$loadAndRun$1$$anonfun$apply$17.appl...
scala>
有人知道如何正确退出此 scala/javafx 应用程序(这样就不需要重新启动 sbt 或 scala 控制台)吗?
When trying to run a simple JavaFX 2.0 beta application written in Scala 2.8.1 from sbt 0.10.1 an exception is thrown after the application window is closed:
> run
[info] Running com.tradex.priceviewer.Main
Exception while removing reference: java.lang.InterruptedException
java.lang.InterruptedException
[ at java.lang.Object.wait(Native Method)success
] at java.lang.ref.ReferenceQueue.remove(Unknown Source)Total time: 5 s, completed Aug 5, 2011 1:12:04 PM
at java.lang.ref.ReferenceQueue.remove(Unknown Source)
at com.sun.glass.utils.Disposer.run(Disposer.java:64)>
at java.lang.Thread.run(Unknown Source)
When running the application from the command line no exception is thrown and the returned status is 0. The code of the application is given below:
class Starter extends Application {
def main(args: Array[String]) {
Application.launch(args)
}
override def start(s: Stage) {
s.setVisible(true)
}
}
object Main {
def main(args: Array[String]) {
val gui = new Starter
gui.main(args)
}
}
After the exception is thrown one has to exit and start sbt again (reload doesn't work). When running the same application from Scala 2.8.1 console the following exception is thrown after the second run:
scala> m.main(Array(""))
scala> m.main(Array(""))
java.lang.IllegalStateException: Application launch must not be called more than once
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:41)
at javafx.application.Application.launch(Application.java:115)
at com.tradex.priceviewer.Starter.main(Main.scala:19)
at .<init>(<console>:11)
at .<clinit>(<console>)
at RequestResult$.<init>(<console>:9)
at RequestResult$.<clinit>(<console>)
at RequestResult$scala_repl_result(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at scala.tools.nsc.Interpreter$Request$anonfun$loadAndRun$1$anonfun$apply$17.appl...
scala>
Would anybody have any clue how to exit this scala/javafx application properly (so one wouldn't need to restart sbt or scala console)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够在我的系统上重现这一点。我发现从 sbt 运行它会生成 InterruptedException,而从命令行运行应用程序运行良好。
我将以下内容添加到 SBT 中的项目设置中:
这告诉 SBT 在与 SBT 本身不同的 JVM 中运行应用程序(和测试)。执行此操作后,我可以多次运行该应用程序并且不会收到 InterruptedException。
我认为您可能在这里遇到的是 SBT 在同一 JVM 中运行应用程序时使用的 SecurityManager。它一定无法处理 JavaFX 应用程序正在执行的任何操作。通过在单独的 JVM 中运行,您可以绕过它。
I was able to reproduce this on my system. I found that running it from sbt generated the InterruptedException while running from the command-line the app ran fine.
I added the following to the project settings in SBT:
That tells SBT to run the app (and tests) in a separate JVM than SBT itself. After doing that I am able to run the app multiple times and do not get the InterruptedException.
I think what you may be running into here is the SecurityManager that SBT uses when running apps in the same JVM. It must not be able to handle whatever the JavaFX app is doing. By running in a separate JVM you bypass that.