|
Page 1 of 6
Google Web Toolkit (GWT) is one of the most popular AJAX frameworks today. It's an open source
framework that makes writing AJAX applications easy for developers. You write your front end in Java
and the GWT compiler converts your Java classes to browser-compliant JavaScript and HTML.
In the book Google Web Toolkit GWT Java AJAX Programming from Packt, author Prabhakar Chaganti provides a step-by-step guide to GWT.
Below is Chapter 2 from the book. Visit PacktPub.com for more information on this book.
Creating a New GWT Application
In this chapter, we will use the GWT tools to generate a
skeleton project structure and files, with and without Eclipse support. We will
then create our first AJAX application (a random quote application) by modifying
the generated application to add functionality and finally run the application
in both hosted and web mode.
The tasks that we will address are:
* Generating a new application
* Generating a new application with Eclipse support
* Creating a random quote AJAX application
* Running the application in hosted mode
* Running the application in web mode
Generating a New Application
We will generate a new GWT
application by using one of the GWT scripts. These helper scripts provided by
GWT create the skeleton of a GWT project with the basic folder structure and
initial project files, so that we can get started in creating our new
application as quickly as possible.
Time for
Action-Using the ApplicationCreator
The GWT distribution contains a command-line script named
applicationCreator
that can be used to create a skeleton GWT project with all the necessary
scaffolding. To create a new application, follow the steps given below:
1.Create a new directory named
GWTBook.
We will refer to this directory location as
GWT_EXAMPLES_DIR. This folder will
contain all the projects that will be created while performing the various tasks
in this book.
2.Now create a subdirectory and name it
HelloGWT.
This directory will
contain the code and the files for the new project that we are going to create
in this chapter.
3.Run the
GWT_HOMEapplicationCreator by
providing the following parameters in the command prompt:
applicationCreator.cmd -out GWTBookHelloGWT
com.packtpub.gwtbook.HelloGWT.client.HelloGWT
The
-out
parameter specifies that all the artifacts be generated in the
directory named
HelloGWT.
The fully qualified class name provided as the last parameter is used as the
name of the class that is generated by the
applicationCreator
script and marked as the
EntryPoint
class for this
application (we will cover the
EntryPoint
class in the next section).
The above step will create
the folder structure and generate several files in the
GWT_EXAMPLES_DIRHelloGWT
directory as shown in the following screenshot:

What Just Happened?
The
applicationCreator script invokes
the
ApplicationCreator class in
gwt-dev-xxx.jar, which in turn
creates the folder structure and generates the application files. This makes it
very easy to get started on a new project as the whole structure for the project
is automatically created for you. All you need to do is start filling in the
application with your code to provide the desired functionality. A uniform way
of creating projects also ensures adherence to a standard directory structure,
which makes it easier for you when you are working on different GWT projects.
Here are all the files and folders that were
automatically created under the
GWT_EXAMPLES_DIRHelloGWT directory
when we ran the
applicationCreator command:
src
HelloGWT-compile.cmd
HelloGWT-shell.cmd
PAGE 1 OF 6
<< Start < Previous 1 2 3 4 5 6 Next > End >> |