2011-08-05 31 views
4

當試圖運行從sbt 0.10.1編寫的Scala 2.8.1中的簡單JavaFX 2.0 beta應用程序時,應用程序窗口關閉後會拋出異常:從sbt運行JavaFx 2.0 beta應用程序時引發InterruptedException 0.10.1

> 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> 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> 

會有人有任何線索如何正確地退出此斯卡拉/ JavaFX應用程序(所以人們不會需要:當運行從斯卡拉同一個應用程序2.8.1控制檯下面的例外是第二次運行後拋出重新啓動sbt或scala控制檯)?

回答

7

我能夠在我的系統上重現這一點。我發現從sbt運行它會在命令行運行時生成InterruptedException,但應用程序運行良好。

添加以下到SBT項目設置:

fork in run := true 

這告訴SBT運行在比SBT本身獨立的JVM的應用程序(和測試)。這樣做後,我可以多次運行該應用程序,並不會得到InterruptedException。

我想你可能會遇到的是SBT在同一個JVM中運行應用程序時使用的SecurityManager。它不能處理任何JavaFX應用程序正在做的事情。通過在單獨的JVM中運行,您可以繞過這一點。

+1

謝謝!這工作非常好。 – Stas

相關問題