Adding Projects to Eclipse
When you first load Eclipse, you are prompted by the dialog box shown in Figure 4-6 for the workspace location. This is the location on your computer that will hold your projects.
Figure 4-6 Loading a workspace in Eclipse
Figure 4-6 shows setting the workspace to C:\Projects and selecting the check box to save this as the default workspace, so the next time Eclipse opens this workspace is automatically loaded. Since this is a new workspace, when the main Eclipse window loads it will not have any projects listed in its Package Explorer. At this point we could start building a project manually in Eclipse for the HelloWorld application built earlier in this chapter, but GWT gives us a shortcut with the projectCreator script shown in Figure 4-7.
Figure 4-7 Creating a project with the projectCreator script and the -eclipse flag
This creates an empty project that references GWT and can be easily loaded into Eclipse. To load the GWT project into Eclipse, choose File > Import to display the Import dialog box, shown in Figure 4-8.
Figure 4-8 Step 1 of importing a generated GWT project into Eclipse
In the Import dialog, select Exiting Projects into Workspace and then click Next. The next page of the Import dialog, shown in Figure 4-9, lets you select the projects you want to import.
Figure 4-9 Step 2 of importing a generated GWT project into Eclipse
In this dialog you first need to select the location of your project files. The dialog then presents the list of possible projects that you can import. Figure 4-9 shows the GwtApps project that we created with the GWT projectCreator script. Make sure this project is checked and then click Finish.
At this point Eclipse loads the project into the Eclipse workspace, and the HelloWorld application is listed under Package Explorer, as shown in Figure 4-10, since it was generated in the Projects directory.
Figure 4-10 The generated GWT project in the Eclipse IDE
You can add other applications to this project using the application Creator script, but since we're in Eclipse now we can take advantage of the -eclipse option with the script. When the HelloWorld application was run this option was not specified, so we do not have any Eclipse-specific files that allow you to launch the application from Eclipse. So let's run the applicationCreator script again, this time specifying the -eclipse option, as shown in Figure 4-11.
Figure 4-11 Creating an application for use in Eclipse
If you're creating a new application for use in Eclipse, you do not need the -overwrite option. This example used this option to overwrite the previously generated application, which did not have Eclipse support. Notice in Figure 4-11 that the new file HelloWorld.launch was created. This launch file allows you to select the Debug or Run command options for the HelloWorld application inside Eclipse. To see this change in Eclipse, refresh your project (right-click on the project and select Refresh), and then run the HelloWorld application in Debug mode by clicking on the Debug icon (see the bug icon on the toolbar in Figure 4-12). If your application isn't listed in the debug drop-down box, which shows a list of recently debugged configurations, you'll need to click Debug... in the drop-down menu to load the Debug dialog. You'll find the launch configuration for the HelloWorld application under Java Application.
Figure 4-12 Running a GWT application in the Eclipse debugger
The application will load in GWT's hosted mode browser, and you can interact with it while still being connected to the Eclipse IDE. This means you can set breakpoints, change code, and perform other Eclipse functions while your application is running. The ability to do this shortens the code-test cycle dramatically and its ease promotes heavy testing.
Attaching GWT development to Eclipse, or any other Java IDE, is a giant step forward for Ajax application development. Let's look at some of the details of writing code with Eclipse.