Setting up a GWT Project
From Zanecorpwiki
Contents |
Getting the Basic Layout
In my opinion, the best way to set up a GWT application/project is to use the 'webAppCreator' tool.[notes 1]
Call the 'webAppCreator' from the directory where you want to create your new module, or from where your existing source code resides (src/ ?). Run the command with '-out' to create the application code it it's own module or leave off '-out' to create the code as part of the existing structure. The only required argument is the package where to put the app code, i.e.: com.foo.Bar.
Twiddling the build.xml
You get a build file generated for you. Unless this is the first and only piece of the application, you'll want to either integrate or otherwise modify the build file to fit into the larger project.
One (common?) task is to add a 'package' and 'deploy' target which takes the GWT project and integrates it into another web app by creating a jar and moving that jar where it needs to go.
<target name="package" depends="clean, gwtc" description="Package up the project as a jar">
<echo>Creating the jar file from our source...</echo>
<jar destfile="Bar.jar">
<fileset dir="war/WEB-INF/classes">
<include name="**/*.class" />
<include name="**" />
</fileset>
<fileset dir="src"><!-- include the source so it's usable by GWT -->
<include name="**/*.java" />
</fileset>
</jar>
</target>
<target name="deploy" depends="package" description="This target deployes the code to the web app">
<copy file="Bar.jar" todir="${deploydir}/WEB-INF/lib/" />
<copy todir="${deploydir}">
<fileset dir="${basedir}/war/publicconsole/" excludes="**/*.cache.xml"></fileset>
</copy>
<!-- this one is temporary, remove it later -->
<copy file="${basedir}/war/Bar.html" todir="${deploydir}" />
<copy file="${basedir}/war/Bar.css" todir="${deploydir}" />
</target>
Twiddling the Generated Class Names
The 'webAppCreator' generates a kind of "Hello World" application. If this is your first time through, you may want to take a look at, launch, and play with these files.
If you fed 'webAppCreator' something like 'com.foo.Bar', then 'com.foo' is the base package. There'll be a Bar.gwt.xml file in the base package as well as two more packages: client and server.
'Bar.java' in the client package is where you set up the GWT interface. Gut the contents of 'onModuleLoad'. Rename the 'greetingService' variable and type to 'BarService' or whatever makes sense in your case. Delete the SERVER_ERROR (or change it).
Now rename 'GreetingService.java' and 'GreetingServiceAsync.java' in the client package and 'GreetingServiceImpl.java' in the server package. You're now free to fill those classes with the interface and implementation necessary to do whatever it is you're trying to do.
Notes
- ↑ There are other methods, such as the Eclipse plugins, but using the command line tool generates a more portable application project. Specifically, the command line tool generates a build script, while the Eclipse plugins do not.


