20 October 2010

Importing GWT SDK Samples into Eclipse

I've recently started working with the Google Web Toolkit (GWT), which seems pretty sweet from everything I've read so far. It has great integration with an IDE, in this case Eclipse, which is absolutely essential.

Unfortunately, it was hard to find a way to easily open GWT's sample projects in Eclipse, but after a little trial and error, here is what I came up with. For each sample project you want to use, do the following:
  1. Create a new Java project with the name of the sample project you want to use, for example, "Hello". Use all the other default settings, and press "Finish".
  2. Right-click on the project and choose "Import". Choose "General" -> "File System", then press "Next".
  3. Browse to the directory of the sample project you want to import. On my computer, the project was found at something like: C:\Program Files\eclipse\plugins\com.google.gwt.eclipse.sdkbundle...\gwt-2.0.4\samples. Select all, then press "Finish".
  4. Right-click on the project and choose "Google" -> "Web Toolkit Settings". Check the "Use Google Web Toolkit" check box.
  5. Go the the "Java Build Path" section of the project's properties. Change the default output folder to something like: "/Hello/war/WEB-INF/classes" (This will be different depending on your project name).
That's all! Good luck and have fun trying out GWT's samples.

7 comments:

Esfand said...

It is easier to CD to the project's root (where the build.xml file is) in a DOS session and then issue the command:

>> ant eclipse.generate

This will create the .project and .classpath that you can use to import the project into Eclipse.

Esfand said...

Or it is even easier if, directly from withing Eclipse, select
File/new/project/Java Project From Existing Ant BuildFile
Then browse to the folder containing the build.xml file. This will import the sample with all the correct settings into Eclipse.

Unknown said...

I tried doing it from the ant build file in eclipse, but no luck.

Esfand said...

More detailed instructions for importing each sample into Eclipse is in the readme.txt file in the root folder of the sample.

Just curious, which sample did you try and how did it fail?

huy k said...

@Esfand: I create Java Project From Existing Ant BuildFile and it create project in workspace path but source project is in eclipse path. So I can't Runs as Ant build becase could not find gwt-servlet.jar.
Must I set workspace for eclipse to \gwt-2.1.1\samples forder?

Anonymous said...

I was able to run the samples by importing them after running ant eclipse.generate. ant created the .classpath and .project files needed.

Akhil said...

Thanks, helped me to import the showcase stuff.