Aborting interrupt when starting JavaFx 2.0 beta application 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 occurs after closing the application window:

> 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 starting the application from the command line, an exception is not generated, and the returned status is 0. The application code is shown 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, you need to exit again and run sbt (reboot does not work). When starting the same application from the Scala 2.8.1 console, the following exception is thrown after the second launch:

 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> 

Does anyone know how to properly exit this scala / javafx application (so there was no need to restart the sbt or Scala console)?

+4
source share
1 answer

I was able to reproduce this in my system. I found that starting it from sbt raised an InterruptedException, when it was launched from the command line, the application was working fine.

I added the following project parameters to SBT:

 fork in run := true 

This tells SBT to run the application (and tests) in a separate JVM than the SBT itself. After that, I can run the application several times and not get an InterruptedException.

I think you can work here, this is a SecurityManager that uses SBT when running applications in one JVM. It should not cope with what a JavaFX application does. By managing individual JVMs, you get around this.

+7
source

All Articles