Code Java, deploy JavaScript/HTML with the Google Web Toolkit
May 18th, 2006
Mike’s reference to Google’s new Web Toolkit piqued my interest. It is quite novel in several ways
- It allow web client developers to code in Java rather than JavaScript. The code is translated prior to “deployment” by a Java-to-JavaScript compiler. The generated Javascript code uses a Javascript-based JRE emulation library that provides “most of java.lang and a subset of java.util”.
- The toolkit UI uses Eclipse SWT and (I’m pretty sure) the Java-to-JavaScript compiler is built on top of the JDT code model. Interesting use of JDT!
- The toolkit ships a command line utility that generates template Eclipse projects. Import the skeleton project into an Eclipse workspace and code away. I had to do a little hacking to use the generated launch configuration file to launch the toolkit from within Eclipse but it works. (Drop a copy of the .launch file into <workspace>\.metadata\.plugins\org.eclipse.debug.core\.launches, restart the workbench and then use Debug… and you’ll see it listed under “Java Applications”). This leads to one of the most powerful features. You can debug your application (as Java) when the toolkit is launched and/or you can write/run JUnit tests. Assuming the toolkit behaves itself when translating it all to Javascript you can be pretty confident the end user experience will be consistent.
- You can mix Javascript into your Java source if things get a little hairy.
- The toolkit uses Tomcat to host the “deployed” Javascript/HTML.
- The Javascript generated code (and library) provides lots of web client development conveniences like browser history management and major browser compatability.
- They’re giving it away for free but they only ship some of the source for the toolkit. It would of course be better if they shipped all of the source for the toolkit itself when integrating that much open source software (Eclipse/Tomcat/Mozilla/Rhino) into a free toolkit. Quid pro quo and all that.
See the overview for all the gory details.
All in all, it is not for the Javascript purists but it looks very handy for all those Eclipse/Java developers out there who occasionally need to knock up a web based application…

‘The generated Javascript code uses a Javascript-based JRE emulation library that provides “most of java.lang and a subset of java.utilâ€.’
holy crap, that has got to craaaaaawl….
Yeah, I was going to post some examples of what the Java->Javascript compiler was producing…but…it was too big (and obfuscated) to make any sense on it’s own!
The more I think about it, the more limited the use cases for this toolkit, even for Eclipse/Java developers. A huge drawback is that the tolkit doesn’t help with calling existing REST/SOAP interfaces from the generated clients – it’s almost a walled garden (see http://web2.wsj2.com/googles_innovative_yet_limited_ajax_environment_gwt.htm)