JavaScript for Cheminformatics: Cross-Compiling Java to JavaScript with GWT 7

Posted by Rich Apodaca Tue, 09 Dec 2008 15:59:00 GMT

A few months ago I wrote about some ways that JavaScript could be used for cheminformatics. Although at the time I was considering mainly cheminformatics tools build from scratch with JavaScript, there is another possibility. Today, Duan Lian posted this intriguing comment:

I think GWT(Google Web Toolkit) is a good starting point. It has the ability of running "Java code" as javascript generated by a special java2js complier.

If you've never heard of Google Web Toolkit, it's a compiler for Java that instead of generating bytecode generates Javascript. It has the capability of producing highly-compact, obfuscated JavaScript that can be efficiently transmitted.

I feel a little dumb for not even considering this possibility. I remember grabbing a copy of GWT just days after it was initially released and compiling a simple 'hello world' application with it. But somehow the idea of using it to cross-compile full-blown Java libraries to JavaScript didn't occur to me. It seemed like something you'd use to build AJAX widgets with.

One problem with this approach could be the limited availability of Java APIs on GWT. Ease of cross-compilation is likely to turn on the dependencies the source code requires, both from core Java itself and externally.

Still I wonder how practical would it be to cross-compile a lightweight cheminformatics library like MX into pure JavaScript? If it worked, imagine the possibilities...

Image Credit: Qba from Poland

Comments

Leave a response

  1. Egon Willighagen Tue, 09 Dec 2008 20:56:49 GMT

    OK, OK, I can no longer keep this to myself...

    What if, just what if we compiled JChemPaint on top of GWT and compile that to JavaScript...

  2. Duan Lian Wed, 10 Dec 2008 15:00:03 GMT

    @Egon

    I wrote an email about this to CDK-devel yesterday, and it's still waiting your approval. :-)

  3. Vfed Wed, 10 Dec 2008 15:22:33 GMT

    GWT has rather limited graphics support - you need to replace everything related to Graphics2D/Canvas with 1x1 coloured DIV's.

  4. Rich Apodaca Wed, 10 Dec 2008 19:55:17 GMT

    Based on what I've seen, I have to agree with Vfed in the sense that cross-compiling complex Swing/AWT dependent code is probably out of reach.

    I'd be impressed if the only thing that was possible was cross-compiling a small Java library like MX.

    Still, that wouldn't be a bad starting point...

  5. Duan Lian Thu, 11 Dec 2008 12:31:25 GMT

    I have got MX compiled and running on GWT with Molfile I/O future. A demo page several hours later.

  6. Rich Apodaca Thu, 11 Dec 2008 14:38:48 GMT

    Duan, that's fantastic! I look forward to seeing the demo. What do you think about setting up a GitHub repository to host the code/build system?

  7. Duan Lian Thu, 11 Dec 2008 15:54:06 GMT

    The demo page is here. http://chemhack.com/mx-gwt/ There're some Chinese character on that page due to my version of wordpress. I suggest you to post that on depth-first for a better view.

    I made a branch from MX, and I'm now trying to find out how to get Git running on Mac OS. Source will be available as soon as I got it running.

Comments