GWT comes with a utility called webAppCreator which does most of this, but also provides a build.xml and JDT launch configuration file:
webAppCreator -out MyWebApp com.mycompany.mywebapp.MyWebApp
In addition to creating the same directory structure and starter app code as the wizard, webAppCreator generates a README.txt file that, among other things, explains how to setup the project in Eclipse:
File -> Import... -> Existing Projects into Workspace
Browse to the directory containing this [README], select "MyWebApp".
Be sure to uncheck "Copy projects into workspace" if it is checked.
Click Finish.
You'll have Eclipse .project and .classpath files, but the project isn't configured for the GWT plugin. To do this, go to the Properties dialog for the project, Google > Web Toolkit. Turn on Use Google Web Toolkit, make sure it knows the location of your GWT installation, and hit OK.
- To run the project using the Development Mode view within Eclipse, select Run As > Run Configurations..., and you should have Web Applications > MyWebApp. Select and run it; to stop it click the red square in the Development Mode toolbar.
- To run the project using the standalone Development Mode java app, select Run As > Run Configurations..., and you should have Java Applications > MyWebApp. Select and run it; the standalone app seems to be a bit more versatile than the Eclipse view, but adds some overhead.
Finally, to package the project into a war fit to be deployed, go to Run > External Tools > External Tools Configurations, and create a new Ant build. Pick the build.xml for your project, your project as the base directory, then move to the Targets tab, and select the war target, deselecting the build target since war depends on build already. It's a good idea to name this Configuration "MyWebApp war" or similar. When the target is run, your code will be compiled into the war subdirectory, which will then be zipped into MyWebApp.war in the project directory.
Thanks a lot for this post. It saves a lot of time trying to import a sample module and run in Eclipse.
ReplyDeleteRyan Nieh
ryan.nieh@gmail.com