Sunday, November 29, 2009

We are 64bit ready, or not?

I got my new DELL XPS 9000 this week after long waiting, and started playing with it with great enthusiasm this weekend.

The computer will be my primary development desktop at home, so I have to install all my toolkits. I'm tired of OutofMemoryException while coding under 32bit OS, and finally I can have more heap size in JVM with this new 64bit powerful machine. :)

First step was very smoothly, I installed JDK 1.6.0_17 from Sun Java Website, and it has Windows x64 vesion.

Next step was to install my favorite IDE, Eclipse for Java EE Developers (Galileo). Wait, I couldn't find 64bit download! I can see 64bit version for Linux, Mac Cocoa, but not for Windows. There is only I downloaded this one, and obviously Eclipse gave me Exception!

Fortunately, someone already figured out and blogged about it. OK, let's download 64bit version of Eclipse SDK, and install my plugins one-by-one. After a really boring setup process, I got my Eclipse running under 64bit JDK!

Then it was time to install my favorite build tool - Maven. Very straightforward. After setting up environment variables, I can run mvn in command line.

At last, I wanted to try GWT with all of those tools, and that really pissed me off. I went through GWT Experience - Create GWT Module Project with Maven GWT Plugin. And I got compiler error when I tried to run the GWT application by Maven:

[INFO] [gwt:run {execution: default-cli}]
[INFO] using GWT jars from project dependencies : 1.7.1
[INFO] Unpack native libraries required to run GWT
[INFO] establishing classpath list (scope = runtime)
[INFO] create exploded Jetty webapp in C:\GWT\test\org.opentoast.admin\war
[INFO] auto discovered modules [org.opentoast.admin.Application]
[ERROR] You must use a 32-bit Java runtime to run GWT Hosted Mode.
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------

What a surprise!

Googling, Googling, and I realized it is the problem in GWT 1.x. This has been raised as issue 134, issue 135, or issue 2880. Here is a good explanation from Dan Morrill at GWT Forum. So basically I have to wait until GWT 2.0 comes out with Out-of-process Hosted Mode (OOPHM) to get 64 bit support. Even right now GWT 2.0 RC2 is here to try, I still cannot use it with Maven, because gwt-maven-plugin won't work, I have to wait for a while until both are released.

Seems the only solution is to switch to 32bit JDK, and use all 32bit tools now. What a waste of time! Well, that's the price I have to pay when I play with new technologies.

Wednesday, November 11, 2009

GWT Experience - Create GWT Module Project with Maven GWT Plugin

I Have played with GWT for quite a long time, reading the book "GWT in Action", trying Tutorials and many blogs (Deploying GWT Applications in SpringSource dm Server, etc.)

Now I feel it is time to add rich client UI to Open Toast project.

Use Maven GWT plugin to create GWT module project

There are many ways to create a GWT application from scratch. Normally people use webAppCreator tool in command line, or use Google Plugin for Eclipse. The problem is the brand new application created by Google tools has different directory and package layout from other Open Toast modules.

We all know Convention over Configuration, and the question is whose convention we follow? Seems GWT team is not following Maven's convention (as far as GWT 1.7.x). But I want to make our development/build/deployment be consistent with Maven, for long term benefit. Fortunately, there is a Maven plugin Mojo Maven GWT Plugin or "gwt-maven-plugin" to solve the problem.

Since release 1.1, mojo gwt-maven-plugin merged with Google Code GWT-maven-plugin, and it is pretty stable now.

So first, I tried to create our administration by gwt-maven-plugin archetype. Inside opentoast root folder, run the command:

mvn archetype:generate -DarchetypeGroupId=org.codehaus.mojo -DarchetypeArtifactId=gwt-maven-plugin -DarchetypeVersion=1.1 -DgroupId=org.opentoast -DartifactId=org.opentoast.admin

During creation, set project version to 0.0.2, and package to After that I have to change several settings in pom.xml. The gwt.version is changed to 1.7.1, the current release; and gwt-maven-plugin version is changed to 1.1 instead of 1.1-SNAPSHOT.

Then I can test the new admin application in hosted mode by command:

mvn -DrunTarget=org.opentoast.admin.Application/Application.html gwt:run

A very simple Web application with just a line of text.

The whole project structure is very consistent with standard Maven project layout, such as src/main/java, src/main/resources, src/main/webapp. But there are still 2 issues I don't feel comfortable with. First, the GWT XML module file is put inside java folder, at src/main/java/org/opentoast/admin/Application.gwt.xml. Second, html and css files are inside resources folder instead of webapp. Application.html and Application.css are located at src/main/resources/org/opentoast/admin/public folder.

From GWT Developer Guide - "Modules: Units of configuration", we know public sub-package under module xml file's located package contains static resources used by the GWT module. Since client code may reference those resources by GWT.getModuleBaseURL() + "resourceName.png", I think better we keep it.

For first issue, I tried to move Application.gwt.xml to resources folder, at src/main/resources/org/opentoast/admin/Application.gwt.xml, and I can still run application in hosted mode, so maybe it is OK to do that.

Rename module name

After running the application in hosted mode, GWT created a folder war in root directory, and compiled Java code into Javascript. The generated Javascript file org.opentoast.admin.Application.nocache.js was put inside war/org.opentoast.admin.Application/ folder. Seems the GWT module name is org.opentoast.admin.Application, which is too long with full package name. It is very easy to change it to a much shorter name admin.

First, update GWT module xml file by adding rename-to attribute to module element:


Next, update Application.html to load correct js file:

Try to launch the application by mvn -DrunTarget=admin/Application.html gwt:run, and it works fine. There is new folder admin inside war, with all public resources and generated js file admin.nocache.js.

Later I tried to integrate this GWT project into the bigger Open Toast Project with quite a few small challenges, and that will be my next blog.