Skip to main content

FXEvaluator failing on OS X and XP

3 replies [Last post]
jonathanbranam
Offline
Joined: 2009-02-06
Points: 0

I am trying to use FXEvaluator to evaluate some JavaFX script on my website to serve as a tutorial for JavaFX. I have tried to use FXEvaluator but it fails in OS X and Windows XP. My OS X is running Java 1.5 and XP is running Java 1.6.

OS X appears to fail when it tries to load a class that has been compiled for Java 1.6. I am guessing this class is part of the Script Engine support in JSR-223 that was added to Java 1.6, but I cannot confirm this. The script fails on XP and complains that it cannot find a script engine.

Does FXEvaluator rely upon JSR-223 and therefore will never work in Java 1.5? Is there a simple step to get JavaFX to register itself with the script engine runtime to fix the problem on XP? Also, is using FXEvaluator considered an unsafe operation that will popup a warning dialog to my users?

This is the JavaFX code:
var l = FXEvaluator.eval('return "hi"');

OS X (Java 1.5 I believe):
standard-run:
java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:675)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:280)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:242)
at sun.misc.Service$LazyIterator.next(Service.java:271)
at javax.script.ScriptEngineManager.initEngines(ScriptEngineManager.java:109)
at javax.script.ScriptEngineManager.access$000(ScriptEngineManager.java:37)
at javax.script.ScriptEngineManager$1.run(ScriptEngineManager.java:80)
at java.security.AccessController.doPrivileged(Native Method)
at javax.script.ScriptEngineManager.init(ScriptEngineManager.java:78)
at javax.script.ScriptEngineManager.(ScriptEngineManager.java:51)
at javafx.util.Evaluator.eval(FXEvaluator.java:35)
at javafx.util.FXEvaluator.eval(FXEvaluator.java:77)
at javafxapplication1.EvalTest.javafx$run$(EvalTest.fx:20)
at javafxapplication1.EvalTest.javafx$run$(EvalTest.fx:20)

XP (Java 1.6, I believe, but JavaFX is targetting 1.5 still):
standard-run:
java.lang.RuntimeException: javax.script.ScriptException: no scripting engine available
at javafx.util.FXEvaluator.eval(FXEvaluator.java:79)
at javafxapplication1.EvalTest.javafx$run$(EvalTest.fx:19)
at javafxapplication1.EvalTest.javafx$run$(EvalTest.fx:19)
Caused by: javax.script.ScriptException: no scripting engine available
at javafx.util.Evaluator.eval(FXEvaluator.java:39)
at javafx.util.FXEvaluator.eval(FXEvaluator.java:77)
at javafxapplication1.EvalTest.javafx$run$(EvalTest.fx:19)
at javafxapplication1.EvalTest.javafx$run$(EvalTest.fx:19)
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 com.sun.javafx.runtime.provider.AWT_EDT_RuntimeProvider$1.run(AWT_EDT_RuntimeProvider.java:104)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jonathanbranam
Offline
Joined: 2009-02-06
Points: 0

I have fixed the problem for Java 1.6 on XP. Apparently, even though the javafxc.jar is listed in the "JavaFX SDK on Java 1.6" under Libraries in NetBeans, it is not actually compiled into the project. Perhaps because the necessary class is simply not referenced? It certainly be convenient if referencing FXEvaluator from a JavaFX script would create a reference to the needed implementation classes.

Adding javafxc.jar directly to the Libraries supplies the JavaFX compiler to the runtime.

However, this does not resolve the problem on OS X when running against Java 1.5. I would imagine the problem would be identical on XP/Vista running 1.5.

Does FXEvaluator require Java 1.6 whereas the core JavaFX only requires Java 1.5 or is there a class somewhere that was mistakenly compiled for 1.6? Of the jars included in JavaFX SDK on Java 1.5, only the rt15.jar claims to have been compiled under Java 1.6. I would imagine the problem lies in one of classes in that jar.

alexsch
Offline
Joined: 2007-07-12
Points: 0

You can download Java Scripting API library from https://scripting.dev.java.net/ and add it to your project as library.

jonathanbranam
Offline
Joined: 2009-02-06
Points: 0

The JavaFX scripting engine is not available for download from that site and the necessary jars are already included in the JavaFX SDK. I didn't make it clear, I suppose, that this was a JavaFX project.

I found, as mentioned in my other comment, that including a direct reference to the javafxc.jar in my project caused the reference to be resolved in XP running Java 1.6, but did not help for Java 1.5 on OS X.