I set up my j2s environment today using j2s from SVN as Zhou
suggested. My goal has been to determine to what extent GC might
already work in Java2Script (I'm assuming it will just work as a
stubbed-out API).
After trying out some simple examples, I decided to attempt to use
some of the simple Draw2d examples. I set this up by pulling
org.eclipse.draw2d and org.eclipse.draw2d.examples into my workspace
from CVS. I made them both Java2Script projects, and then put Draw2d
on the Java2Script build path for Draw2d examples. Happily,
Java2Script didn't seem to have any trouble building either of the two
projects, as I could see .js files corresponding to each .class file
in the build dir.
Unfortunately, when I attempted to run the HelloWorld example in
org.eclipse.draw2d.examples, it complained with the following error
message:
[Java2Script] Error in loading ../bin/org/eclipse/draw2d/FigureCanvas.js!
[Java2Script] Error in loading ../bin/org/eclipse/draw2d/Label.js!
I opened the top-level html file in Firefox using the file URI
handler, in order to debug it in Firebug, and it did indeed appear
that org.eclipse.draw2d.FigureCanvas was undefined. However,
FigureCanvas.js did appear to have been built correctly. It was my
suspicion that for some reason the j2s class load was not able to find
FigureCanvas.js. Unfortunately, when using the file handler, Firebug
does not active the Net panel, so I turned on a local HTTP server and
set the server root to my workspace.
What I discovered was that the class loader was attempting to load the
following path:
http://localhost/bin/org/eclipse/draw2d/FigureCanvas.js
Where it should have been trying to load:
http://localhost/org.eclipse.draw2d/bin/org/eclipse/draw2d/FigureCanvas.js
So, for some reason it was leaving off the project name. I assume it
was doing the same thing for the file URI. Does anyone have any idea
why it might be doing this?
I temporarily worked around this problem by setting a symlink in the
root of my workspace to org.eclipse.draw2d/bin. After that, it still
failed to pull in a dependency, but I believe this other problem was
different. Draw2d requires java.beans.PropertyChangeListener, and it
attempted to pull it in from j2slib, so:
But j2slib does not emulate this API. This is fine, and it shouldn't
be too difficult to wrap this by hand, but I'm wondering why the j2s
compiler did not catch it. Does the j2s compiler not do static
analysis on the code to catch unmet dependencies?
Also, when implementing the java.beans API, will it be necessary for
me to put this code in j2slib, or is there a way to put this in my own
project? I ask, because, GWT gives you a mechanism for implementing
your own JRE emulation (the "super-source" tag for their GWT modules).
They use this mechanism internally, and also expose it to users. This
allows you to build on the JRE emulation that they provide, in such a
way that it is not necessary to hack on the core. Does j2s provide a
similar mechanism to add to the jre emulation provided by j2s?
I'd appreciate any guidance you can offer on the above three questions. Thanks,
Jake