Yesterday I wanted to import some Google Web Toolkit sample projects into Eclipse. Easy, isn't it?
I was at a customer's site and my purpose was to show them what GWT is and a bit of what it is capable of. So, I downloaded the latest GWT (1.4.61) and installed it.
Edit: As a side-note for those who do not know GWT yet, this is a truly revolutionary way to develop web applications. You code in Java, much in the same way you would code a Swing app. Then a compiler translates your Java code into Javascript, so that it can be executed in the client browser! And it does so taking into account all the details of different browsers' quirks and differences. Basically, you code and - even more importantly - debug your application in Java, and then deploy it as a Web 2.0 Javascript application!
My customers use a well-known IBM product based on Eclipse, so they wanted to see GWT code in Eclipse.
Now, GWT has a nice samples directory, so what I wanted to do was to load the first sample ("Hello") as an Eclipse project. I vaguely remembered that there was some script which could generate Eclipse-related files, so I checked the docs for it.
So I started from the Getting Started guide (no less!) and skimming through it I found this:
GWT ships with a command line utility called applicationCreator that automatically generates all the files you'll need in order to start a GWT project. It can also generate Eclipse project files and launch config files for easy hosted mode debugging, as described below.Okay, that's it!
I started applicationCreator without arguments, and it printed:
Missing required argument 'className'
Google Web Toolkit 1.4.61
ApplicationCreator [-eclipse projectName] [-out dir] [-overwrite] [-ignore] className
where
-eclipse Creates a debug launch config for the named eclipse project
-out The directory to write output files into (defaults to current)
-overwrite Overwrite any existing files
-ignore Ignore any existing files; do not overwrite
and
className The fully-qualified name of the application class to create
So after checking the script parameters, here's what I did, in a new empty directory:
> applicationCreator.cmd -eclipse Test com.example.client.TestThis created a convenient project structure, and even a Test.launch Eclipse launch configuration file, but there was no trace of a .classpath or a .project file.
I tried to import the project into Eclipse anyway, but of course there was no project to be imported! Strange... Why is the launch file generated without a corresponding project file? I began to suspect that there might be a bug (oh, suspicious me!).
I tried to hack a project file, but I was basically on my own there and I had only so many minutes before losing my audience. I was literally losing my opportunity of promoting GWT to these people, and over a detail!
Well, to make a long story short, after some moments of perplexity I resorted to googling about this, and I quickly found this interesting Issue 443! Here is an excerpt from what a user reported:
Basically, I got confused about how projectCreator and applicationCreator were related to one another. The text implies that applicationCreator generates an Eclipse project file, but that's what projectCreator does.Great! What happened was that I too was confused by the wording in the guide into thinking that applicationCreator can generate Eclipse project files. (Read it again!)
What the guide is really trying to explain is this: GWT ("It") can also generate a project as described below. "Below" means in the next section of the guide, which talks about the projectCreator.
After discovering this, it was easy. In fact, those scripts can be run even on an existing GWT source tree!
So, in the original samples/Hello directory I did:
> projectCreator.cmd -eclipse Hello
> applicationCreator.cmd -eclipse Hello -ignore com.google.gwt.sample.hello.client.HelloVoilĂ , the existing sample Hello was augmented with an Eclipse project structure! (Note the -ignore option above, used to work on an existing directory structure.)
Lessons I learned for the future:
- Read the docs carefully and don't jump to conclusions.
- If you are stuck and the project has an issue tracking system, check it!
- Don't try to hack your solution, only to search the forums after that. Do it the opposite way!
- Don't think that you already knew this ;-)