- Download and install the current version of GWT for your platform. Instructions and binaries are here. Put the install directory in your path.
- Obtain the GWT plugin. This example currently only works with the 1.0 version. You need to get it from here and then after unzipping it cd into the expanded folder and run the command:
maven plugin:install-now
- Then you need to get the GWT jar files (and .dll's) into your Maven repository. You'll find them in your GWT install directory. I copied them to a new
./.maven/repository/com.google.gwt/jars/
folder. I had to placegwt-dev-windows.jar
,gwt-servlet.jar
,gwt-user.jar
,swt-win32-3235.dll
andgwt-ll.dll
in there to get this all to work fine. NOTE: You could get the jars automatically too but I was behind a firewall and too lazy to set up Maven to get through it. - Now you can create your new GWT project. Create a directory (e.g. "
./sample/
") to house your project somewhere sensible, change directory into it and run the following command:applicationCreator com.mydemo.gwt.client.SimpleDemo
.This will create you a source code directory ("./src/
") containing a hello world-style GWT application and two scripts for compiling and running your app. - Now we need to mavenise the directory structure. To do this change directory into
./src/
and create three new directories calledjava
,webapp
andtest
. Then move the auto generatedcom
directory and it's contents into the new./java/
folder. NOTE: We won't use thewebapp
directory this time, but it's where we would put things like theweb.xml
file if we had servlets as part of this application. - Finally we need to create the required maven config files as follows which all live in the project root directory ("
./sample/
" in our case). NOTE: You'll need to edit the bits in red to suit your app and workstation:
project.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<pomVersion>3</pomVersion>
<artifactId>mydemo</artifactId>
<groupId>com.mydemo.gwt</groupId>
<currentVersion>0.1</currentVersion>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>user</artifactId>
<version>1.0.20</version>
<jar>gwt-user.jar</jar>
<type>jar</type>
<properties>
<war.bundle>true</war.bundle>
</properties>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<version>windows</version>
<type>jar</type>
</dependency>
</dependencies>
<name>GoogleWebToolkit and Maven Demo</name>
<package>com.mydemo.gwt</package>
<logo>/images/logo.gif</logo>
<inceptionYear>2005</inceptionYear>
<build>
<sourceDirectory>src/java</sourceDirectory>
<unitTestSourceDirectory>src/test</unitTestSourceDirectory>
<!-- Unit test classes -->
<unitTest>
<includes>
<include>**/*Test.java</include>
</includes>
</unitTest>
<resources>
<resource>
<directory>src/java</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
</build>
</project>
maven.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:j="jelly:core">
<preGoal name="war:war">
<attainGoal name="gwt:compile"/>
</preGoal>
</project>
project.properties:
maven.war.src=src/webapp
google.webtoolkit.home=C:\Program Files\GoogleWebToolkit\gwt-windows-1.2.22
google.webtoolkit.runtarget=com.mydemo.gwt.SimpleDemo/SimpleDemo.html
google.webtoolkit.compiletarget=com.mydemo.gwt.SimpleDemo
google.webtoolkit.logLevel=SPAM
That's it, you're ready to go. Just run the maven target "gwt" and you'll see your app in the google debugger.
NOTE: This borrows heavily from an introduction to the maven GWT plugin created by Rober Cooper. His article on O'Reilly can be found here and the google code project for the plugin is here.
2 comments:
The problem I found with this approach is that making gwt:compile a pregoal of war:war results in war:webapp getting run twice (because it is a prereq for both gwt:compile and war:war) and that results in your unit tests getting run twice. As a hack I've prefixed the attainGoal with a j:set var maven.test.skip=true.
Cheers Todd,
Great comment. I'll give it a try.
Post a Comment