Google Web Toolkit 2 Application Development Cookbook
上QQ阅读APP看书,第一时间看更新

Creating a GWT project in NetBeans

All the required tools and technologies are installed. Now, we will create the Java Web project using the Google Web Toolkit Framework in NetBeans.

Getting ready

Make sure that GWT and GlassFish are installed, the GlassFish server is added, and the GWT4NB plugin is installed in NetBeans.

How to do it...

  1. Start NetBeans.
  2. Go to File | New Project.
  3. Select Java Web from the Categories field, and Web Application from the Projects field, as shown in the following screenshot:
    How to do it...
  4. Click on Next.
  5. Give Sales Processing System as the Project Name, browse the Project Location, and check Set as Main Project:
    How to do it...
  6. Click on Next.
  7. Select GlassFish v3 from the Server list, and Java EE 6 Web from the Java EE Version.
  8. Set the Context Path, or leave it as suggested. It is the path to the "root directory" of a web application (called the context root), relative to the root of the web server namespace.
    How to do it...
  9. Click on Next.
  10. Select Google Web Toolkit from the list of frameworks, browse for the GWT SDK Installation folder (such as C:\Program Files\gwt-2.0.3, or any other location where you have installed it), and name the GWT Module as com.packtpub.Main:
    How to do it...
  11. Click on Finish on completion of the installation.

How it works...

After following the aforementioned steps, a NetBeans project structure with some sections containing the following files has been created:

  • Web Pages

    WEB-INF

    • sun-web.xml
    • web.xml

    welcomeGWT.html

  • Source Packages

    com.packtpub

    • Main.gwt.xml

    com.packtpub.client

    • MainEntryPoint
  • Libraries

    GWT2.0.3-gwt-user.jar

    gwt-dev.jar

    gwt-servlet.jar

    JDK1.6

    GlassFish v3

How it works...

Directory and file structure

A directory and file structure is created, as shown in the following screenshot:

Directory and file structure

Running the project

A default code is given in the MainEntryPoint.java file. That's why, we can run the project to see a basic output. To run the project, right-click on Sales Processing System under Projects and then click on Run, as shown in the following screenshot:

Running the project

The following events take place:

  1. GlassFish is started automatically, if it is not started yet. It will prompt the user for the username and password. Provide "admin" as the username and "adminadmin" as the password (or as we had set during the installation of GlassFish).
  2. The project is compiled by GWT Compiler.
  3. The project is deployed to the \Sales Processing System\build\web directory.
  4. The default browser is called with the URL http://localhost:8080/Sales_Processing_System/.
  5. The output is a button labeled Click me!. If the button is clicked, a label, Hello, GWT!!!, is hidden and displayed alternately:
    Running the project