How To Fix The FXEvaluator On Java FX 1.2 and JDK 1.6

A simple invocation of the FXEvaluator:

 var output = FXEvaluator.eval("{2+3}");


Will cause the following error on JavaFX SDK 1.2 and JDK 1.6 (Mac OS X):

java.lang.NoClassDefFoundError: com/sun/tools/javafx/script/JavaFXScriptEngineFactory
        at javafx.util.Evaluator.eval(
        at javafx.util.FXEvaluator.eval(
        at dynamicfx.Main.javafx$run$(Main.fx:17)
        at dynamicfx.Main.javafx$run$(Main.fx:17)

It seems like the JSR-223 runtime is not in the JavaFX classpath. Only JDK 1.5 classes are included in the compilation and runtime classpath. Including JDK 1.6 classes directly to the JavaFX-runtime will cause another runtime-error. It seems like the Java FX SDK comes with a modified javac compiler.

To fix the problem, just prepend the script-api.jar and the javafxc.jar to the bootclasspath. This is easily possible in the file ${javafx_home}/profiles/ Just change the entry from:

# execute_bootclasspath_prepend=



You don't have to change anything in the IDEs. It just works in netbeans 6.5.1 FX and eclipse 3.5. After this fix, you will be even able to evaluate Java FX dynamically inside the already dynamic script :-):

var output = FXEvaluator.eval("{2+3 + (javafx.util.FXEvaluator.eval('{2}') as Number)}");

Moving the whole value of the execute_classpath into the execute_bootclasspath_prepend with both jars (see above) prepended fixes the problem as well.


Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments