InterruptedException thrown when running JavaFx 2.0 beta app from sbt 0.10.1
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
开发者_JAVA技巧 [ 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)?
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.
精彩评论