I have decided that it was time for me to take a look a Google Web Toolkit. In this post I will share my experiences with setting up my build using Maven 2 (do we really still need to version the maven name? Anybody starting new projects using Maven 1?).
You may see following posts about my GWT experiences as my, in the moment, experimenting application evolves to take over the world...
To start somewhere I found a Maven 2 GWT archetype which I gave a try. I found the archetype through a Google Group so you need to download the archetype from here and build it. Just unzip and run mvn install.
The archetype is designed for use inside Eclipse. My favorite IDE is Intellij IDEA, but never mind the Eclipse files .project, .classpath and a .launch file can just be deleted.
With the magic line(s) beautifully expressed in a non verbose way ;-) I created my project:
mvn archetype:create -DarchetypeGroupId=com.totsp.gwt -DarchetypeArtifactId=gwt-archetype -DarchetypeVersion=1.0-SNAPSHOT -DartifactId=foobar -DgroupId=foo.bar
The archetype in use uploaded the 12. of June references the latest stabile release of GWT version 1.3.3. In the time of writing there is a version 1.4 RC (1.4.10). I updated my pom.xml to point to this new version.
For interaction with GWT through maven I have used the plugin as provided with the archetype maven-googlewebtoolkit2-plugin.
Simply add something like the following to your settings.xml:
<profile>
<id>gwt-1.4.10</id>
<properties>
<google.webtoolkit.home>/usr/local/gwt/gwt-mac-1.4.10</google.webtoolkit.home>
<google.webtoolkit.extrajvmargs>-XstartOnFirstThread</google.webtoolkit.extrajvmargs>
</properties>
</profile>
and remember to activate the profile for your build. This will also let the plugin be aware of where your local GWT installation is. If you are running on Mac OS X, as I am, remember to set -XstartOnFirstThread. Otherwise the GWT browser cannot start.
Having this in place I was able to start my build by running 'mvn gwt:gwt'. This goal runs just after the Maven package phase and will start the GWT browser launching my app.
Thanks to the archetype I was up running in no time. It gives me a head start in how to organize my project structure and has some important initial configurations for the gwt plugin. Of course I have not yet tried the full capabilities (or lacking) of the various goals of the plugin.
I also tried using the maven jetty plugin and this worked for me NOT using the mvn jetty:run, but the mvn jetty:run-exploded goal. Using the run-exploded goal lets maven run the war plugin and Jetty will look in the target folder and not directly in the source folders. Not sure yet why looking directly in the source folders causes some GWT problems, but for now I will just use jetty towards the exploded war in the target folder.
In time I will found out how good my development cycle will be when beginning to actually add code to the application...
15 comments:
good article (in principle) as it looks like exactly what I need to get going. However, doesn't work for me ;-(
I get a couple of errors
1. 'unable to parse module: com.google.gwt.user.User' then a stack trace about can't merge web.xml with causing exception java.net.UnknownhostException
2. if I comment out the mergexml goal I get an error about unable to set catalina.base
I guess the second may be to do with the first not running successfully?
Very new to gwt, but had some experience with m2 so not a complete novice.
Is there something obvious I should be doing more than what you have posted? I have followed to the letter the above.
thanks
Hi Conrad,
1. I get the same message. It doesn't say anything about the severity of the message and I am not sure why it even occurs. Haven't had time to look into it. Please let me know if you can shed some light on this :-)
2. I do not get the "UnknownhostException" when running the mergexml (or other) goal. I did notice something though - we I was sitting behind a proxy I had to configure the proxy for maven for being able to complete the build cycle. Even though running in offline mode the gwt goals timed out.
Hey Claus!
Thanks for this tutorial... I have been reading up a bit on GWT, and will soon begin the process of converting 'academic knowledge' to practical experience... You're post is gonna get me there pretty quickly...
As for the "mvn jetty:run" bit, I think that has to do with the fact that it takes an invocation of GWT compiler to change the source code into the 'end result' code...
Jetty doesn't natively understand this 'crazy gwt-speak' as it exists in the source code, but it does understand what to do with the post-gwt-compile output that gets put into the target folder.
Regarding Claus Myglegaard Vagner's problems: I have the same problems, but only when my laptop has no internet connection. It looks like the script is trying to resolve a .dtd reference?
thanks a lot !
I keep getting a build error saying I'm missing something in the pom:
--
One or more required plugin parameters are invalid/missing for 'gwt:mergewebxml'
[0] inside the definition for plugin: 'maven-googlewebtoolkit2-plugin'specify the following:
<configuration>
...
<compileTargets>VALUE</compileTargets>
</configuration>
when trying to run 'mvn gwt:gwt'. The app is the default generated by the mvn gwt plugin.
Any idea what might be causing that?
Hi Thomas,
The maven-googlewebtoolkit2-plugin has changed configuration from using
<compileTarget>...</compileTarget>
to
<compileTargets>...</compileTargets>
It must have been a change from version 1.5.3 to 2.0-beta.
Try using the above config instead...
Unfortunately this hasn't been updated in the latest gwt archetype: GWT-ArcheType-Eclipse.1.4.59.zip
Hi Claus,
I search the net for the GWT and maven 2 tutorial and i found out your article is the best. i followed every instructions in there and tried running using "mvn gwt:gwt" i got an error that says:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gwt/dev/GWTCompiler
I currently use gwt-1.4.61 and java 1.5 in my linux box.
Have you encountered this problem?
Thanks,
harold
Hi Harold,
No, I haven't encountered this exception.
I'm shooting blind, but couldn't this problem be related to your local GWT installation? It seems pretty strange that the GWTCompiler can not be loaded.
Regards Claus
Hi Harold,
Try
in pom.xml for plugin maven-googlewebtoolkit2-plugin to add <gwtHome> element like that
<configuration>
<gwtHome>/usr/local/gwt/gwt-1.4.61/</gwtHome>
....
Andriy.
I could not find required archetype zip at mentioned site.Do you have any idea,how to get it ? Thanks in advance.
@Dev,
I think the archetype is in some SVN repo now. Try to check the following discussion
Regards Claus
Thanks for your tutorial. Switching from "jetty:run" to "jetty:run-exploded" saved my day :)
I agree - the run-exploded saved my head from exploding. Thanks!
Yes! Thank you. Using run-exploded prevented my head from exploding. Nice one.
Post a Comment