从 sbt 0.10.1 运行 JavaFx 2.0 beta 应用程序时抛出 InterruptedException

发布于 2024-11-27 23:43:57 字数 2068 浏览 2 评论 0原文

当尝试从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怀念你的温柔 2024-12-04 23:43:57

我能够在我的系统上重现这一点。我发现从 sbt 运行它会生成 InterruptedException,而从命令行运行应用程序运行良好。

我将以下内容添加到 SBT 中的项目设置中:

fork in run := true

这告诉 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:

fork in run := true

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文