I'm trying to run a simple ScalaFX program that displays a window with nothing on it.
I can run the program as a script file with the desired result, but the moment I add a main object to the program it still runs but doesn't produce a window. I can compile the non-script file, but if I try to run it I get the following errors:
java.lang.NoClassDefFoundError: scalafx/application/JFXApp$PrimaryStage
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at scala.reflect.internal.util.ScalaClassLoader.run(ScalaClassLoader.scala:95)
at scala.reflect.internal.util.ScalaClassLoader.run$(ScalaClassLoader.scala:91)
at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:125)
at scala.tools.nsc.CommonRunner.run(ObjectRunner.scala:22)
at scala.tools.nsc.CommonRunner.run$(ObjectRunner.scala:21)
at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:39)
at scala.tools.nsc.CommonRunner.runAndCatch(ObjectRunner.scala:29)
at scala.tools.nsc.CommonRunner.runAndCatch$(ObjectRunner.scala:28)
at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:39)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:66)
at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:85)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:96)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:101)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
Caused by: java.lang.ClassNotFoundException: scalafx.application.JFXApp$PrimaryStage
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 19 more
What am I doing wrong?
// Script file that works
import scalafx.application.JFXApp
val app = new JFXApp {
stage = new JFXApp.PrimaryStage {
title = "First GUI"
}
}
app.main(args)
// I run this in powershell with the following command:
//scala -cp .\scalafx.jar .\program.scala
// Program (non-script file) that doesn't give any errors when compiled but won't run. I can run this as a script file, but no window appears.
import scalafx.application.JFXApp
object Window extends JFXApp {
stage = new JFXApp.PrimaryStage {
title = "First GUI"
}
}
// I compile this in powershell with the following command:
//scalac -cp .\scalafx.jar .\program.scala
// And run with this command:
// scala Window
The compiled program generates the following names for class files (if that helps any):
Window$$anon$1.class, Window$.class, Window$delayedInit$body.class, Window.class,