I created a simple JavaFX applet and compiled it with "javafxc" and created a jar "HelloApplet.jar". Then, I created a simple HTML file as follows:
<script src="http://dl.javafx.com/dtfx.js"></script>
<script>
javafx(
{
archive: "HelloApplet.jar",
draggable: true,
width: 150,
height: 100,
code: "hello.HelloApplet",
name: "HelloApplet"
}
);
</script>
When viewing the HTML, I did not see the expected applet content in it - just a gray rectangle panel
Then, I turned on the "Show Java Console" option. I saw the following exception trace in Java console:
JNLPAppletLauncher: static initializer
Exception in thread "AWT-EventQueue-2" java.lang.NoClassDefFoundError: com/sun/javafx/runtime/FXBase
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)
[.. more stack frames deleted for brevity ..]
Aha! com.sun.javafx.runtime.FXBase is new since JavaFX 1.2. Yes, I had compiled my applet with JavaFX 1.2 (full version "1.2.0_b233"). So, the JavaFX runtime used turned out to be old one! I changed the HTML script URL from http://dl.javafx.com/dtfx.js to http://dl.javafx.com/1.2/dtfx.js. The applet worked as expected
You may have browsed JavaFX API docs generated by javafxdoc tool. javafxdoc tool is implemented as a doclet. It is possible to use javafxdoc's doclet to generate API docs for Java code.
Note: The XMLDoclet implemented as part of javafxdoc tool is an implementation detail and not part of official JavaFX/tool API and so please do not depend on this. This is more for fun/learning/personal use!)
I generated javadoc for BTrace source using the following command:
javadoc -docletpath $JAVAFX_HOME/lib/shared/javafxdoc.jar -doclet com.sun.tools.xmldoclet.XMLDoclet -sourcepath . -subpackages com.sun.btrace
where JAVAFX_HOME is the directory where JavaFX SDK lives.
A screenshot from generated docs:
Do you live in India? What do you want? Sony Ericsson phone or Canon Camera or iPod? If so, have fun writing JavaFX code and win any of these prizes!
JavaFX compiler has a built-in script shell - Per Bothner has implemented a read-eval-print loop facility for JavaFX. The script shell class is com.sun.tools.javafx.script.ScriptShell.
Note:This is in the openjfx-compiler repository and not in the JavaFX 1.0 binary.
A sample JavaFX session is as follows:
$ java -cp dist/lib/shared/javafxc.jar com.sun.tools.javafx.script.ScriptShell
/*fx1*/ "hello"
hello
/*fx2*/ 2 + 4
6
/*fx3*/ function greet (name) { println("Hello, {name}") }
/*fx4*/ greet("Sundar")
Hello, Sundar
/*fx5*/ var s = [ "Sunday", "Monday", "Tuesday" ]
[ Sunday, Monday, Tuesday ]
/*fx6*/ for (i in s) println(i)
Sunday
Monday
Tuesday
/*fx7*/ class Person { public var name: String; }
/*fx8*/ var p = Person { name: "Sundar" }
fx7$Person@13fba1
/*fx9*/ p.name
Sundar
/*fx10*/ import javax.swing.*;
/*fx11*/ var f = new JFrame("hello");
fx11:1: cannot find symbol
symbol : class JFrame
location: class fx11
/*fx12*/
/*fx13*/ var f = new javax.swing.JFrame("hello")
javax.swing.JFrame[frame0,0,0,0x0,invalid,hidden,layout=java.awt.BorderLayout,title=hello,resizable,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,0,0x0,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
/*fx14*/ f.setSize(300, 300)
/*fx15*/ f.setVisible(true)
While there is a generic shell called "jrunscript" for languages that implement jsr-223, it does not work very well for statically typed languages (which can be said about jsr-223 itself). But, the above mentioned JavaFX script shell is independent of jsr-223 interface.
Besides, jrunscript crashes for JavaFX!
$ jrunscript -cp dist/lib/shared/javafxc.jar -l javafx
fx> "hello"
Exception in thread "main" java.lang.NoSuchMethodError: com.sun.tools.javac.main.RecognizedOptions.getJavacFileManagerOptions(Lcom/sun/tools/javac/main/RecognizedOptions$OptionHelper
[Lcom/sun/tools/javac/main/JavacOption$Option;
at com.sun.tools.javac.util.JavacFileManager.(JavacFileManager.java:973)
at com.sun.tools.javafx.api.JavafxcTool.getStandardFileManager(JavafxcTool.java:102)
at com.sun.tools.javafx.script.JavaFXScriptCompiler.(JavaFXScriptCompiler.java:87)
at com.sun.tools.javafx.script.JavaFXScriptContext.(JavaFXScriptContext.java:45)
at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.getJavaFXScriptContext(JavaFXScriptEngineImpl.java:61)
at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.getJavaFXScriptContext(JavaFXScriptEngineImpl.java:55)
at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.parse(JavaFXScriptEngineImpl.java:220)
at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.eval(JavaFXScriptEngineImpl.java:173)
at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.eval(JavaFXScriptEngineImpl.java:164)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:247)
at com.sun.tools.script.shell.Main.evaluateString(Main.java:280)
at com.sun.tools.script.shell.Main.processSource(Main.java:249)
at com.sun.tools.script.shell.Main.access$100(Main.java:19)
at com.sun.tools.script.shell.Main$1.run(Main.java:165)
at com.sun.tools.script.shell.Main.main(Main.java:30)
This is because JavaFX compiler code depends on modified javac classes. The code for jrunscript lives in tools.jar along with the unmodified javac classes! These unmodified javac classes are loaded which results in exception from javafxc code! We have to use the bootstrap path workaround as shown below:
$ jrunscript -J-Xbootclasspath/p:./dist/lib/shared/javafxc.jar -l javafx
fx> 233 + 334
567
fx> for (i in [0..4]) println(i)
0
1
2
3
4
fx>
But, now we have a much better ScriptShell for JavaFX
We don't need to resort to this hack...
There is an unsupported (read - can be removed in future without notice!) command line option with JavaFX compiler. If you run javafxc as
javafxc -XDdumpjava Test.fx
the compiler generates intermediate Java code for your JavaFX program in "./dumpjava" directory (compiler expects you to create ./dumpjava directory before invoking javafxc). This is meant to be a debugging option for JavaFX compiler developers. But, you can look at generated Java code to see what happens behind the scenes - much like C++ programmers used to look at intermediate C code and/or preprocessed code.
I missed attending and speaking at Sun Tech Days at Hyderabad due to a personal reason
In fact, I prepared slides for a talk titled "JavaFX for Java, JavaScript programmers". This is much like my earlier language comparison blog entries such as Java, JavaScript and Jython, Java, Groovy and JRuby etc. The idea is to learn a language by language comparison - and not to conclude "better"/"worse" language and so on. So, no politics please
Although I could not attend Sun Tech Days, I am posting the slides here :
slides in a .pdf file