Introduction
Google Web Toolkit (from Google, at Google Code) is a fantastic framework with a very interesting concept - write in Java run in JavaScript! This article demonstrates how to get started with Google Web Toolkit.
The first part of the article demonstrates how to use the default tools provided in GWT to write the "Hello World" application. The second in the series will demonstrate how to use Cypal Studio Plug-in for Eclipse to make your life easy when it comes to creating, compiling and running GWT applications.
As usual, the code is available in the Downloads section. Direct link to the Google Web Toolkit category is here.
What you need to know
You will need to know Java, at the least because, as I mentioned earlier, majority of the code is written in Java. And please, no generics.
Step 1: Getting Started
Well, the first step is to download Java SDK, if you already don't have one. And then, you will need GWT.
Here's the list, bulleted:
I don't think there should be any trouble to download and install.
Step 2: Looking at GWT
Browse to the folder where you extracted Google Web Toolkit. The folder structure should be similar to shown below.
Step 3: Creating GWT Application
The very first step that you will do with GWT, after all installation, is to create a GWT Application.
If you look at the files, you will notice a file applicationCreator.cmd. You guessed it right, that's our starting point.
At the command prompt, go the folder and issue the following command:
applicationCreator.cmd -out gwt-hello-world com.edujinilabs.tutorials.gwt.hw.clent.HelloWorld
You will notice a set of files created for you.
Step 4: Launching Application in 'Hosted' Mode
Descend into the folder gwt-hello-world. You will notice two files - HelloWorld-compile.cmd and HelloWorld-shell.cmd
Launch HelloWorld-shell.cmd. You will notice two windows opened - one titled "Google Web Toolkit Development Shell / Port 8888" and the other titled "Wrapper HTML for HelloWorld".
In the second window, click the button that reads "Click me". Voila! It says, "Hello World!".
Where's the code?
If you go into the folder gwt-hello-world/src/com/edujinilabs/tutorials/gwt/hw/client, you will notice HelloWorld.java. Yes, that's where the original code is.
Where's the JavaScript?
Ok! I agree. Browsers do not, yet, natively run Java code. So, where's the JavaScript? It's hidden right now. Let's generate.
On the command prompt, issue the following command (in the same folder as where you issued HelloWorld-shell.cmd:
HelloWorld-compile.cmd
Descend into the folder www/com.edujinilabs.tutorials.gwt.hw.HelloWorld. You will notice two files - HelloWorld.html and com.edujinilabs.tutorials.gwt.hw.HelloWorld.nocache.js. Now, that's where the code is.
Conclusion
Well, without getting into even a single line of code, we have been able to say, "Hello World!" using Google Web Toolkit. We have been able to get a peek into where the original Java code resides, and where do we get the compiled / generated JavaScript and HTML content.
We shall explore Google Web Toolkit in greater depth in next articles. Keep watching the category Google Web Toolkit / GWT