Tuesday, July 15, 2014

Getting GWT and AppEngine working together using Maven

Turns out that the gwt-maven-plugin does most of the work for you as long as you are using eclipse and the eclipse google plugin.  The server configuration setting in the POM.xml does everything that you need.  See the POM.xml snippet below.

Here are a couple of gotchas:
  1. You need to use the eclipse plugin to turn on appengine support.
  2. You'll need to create an appengine-web.xml
    • Note that when I tried deploying to appengine even though my app_id was correct in the appengine-web.xml file I would get an error saying that the app didn't exist on appengine and the details showed that it was using the wrong app_id.  I couldn't find where eclipse was getting the incorrect app_id from so eventually just deleted all of the eclipse stuff (mvn eclipse:clean) and reimported.
  3. You'll have to adjust your build path and move the maven dependencies to the bottom of the "order and export" list.  Otherwise eclipse complains that the appengine-sdk.jar is not a directory.
  4. When I reimported my project into eclipse for some reason the target/generated_sources directory was no longer in the java build path.  Add that back in if you get errors about the _async classes not being found.
  5. I had to use eclipse-ee in order to import the maven project properly because it seems like m2e-wtp is required.  I wound up installing the latest version of m2e after getting errors about maven, but that was back when I was trying to run the whole project as a maven project using (appenging:devserver).  I never did get that method of doing this working.  It seems that if you are going to sue the gwt-maven-plugin, you can't combine it with the appengine-maven-plugin.

<!-- GWT Maven Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.6.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
<goal>i18n</goal>
<goal>generateAsync</goal>
</goals>
</execution>
</executions>
<!-- Plugin configuration. There are many available options, see gwt-maven-plugin 
documentation at codehaus.org -->
<configuration>
<strict>true</strict>
<extraJvmArgs>-Xss1024K -Xmx1024M -XX:MaxPermSize=256M</extraJvmArgs>
<logLevel>INFO</logLevel>
<style>${gwt.style}</style>
<copyWebapp>true</copyWebapp>
<hostedWebapp>${webappDirectory}</hostedWebapp>
          <runTarget>gwtmodule.html</runTarget>
<webappDirectory>${webappDirectory}</webappDirectory>
<server>com.google.appengine.tools.development.gwt.AppEngineLauncher</server>
          <i18nMessagesBundle>com.corecompetency.gwt.client.Messages</i18nMessagesBundle>
<appEngineVersion>${appengine.target.version}</appEngineVersion>
<!-- Should GWT create the Story of Your Compile Report -->
<compileReport>false</compileReport>
</configuration>
</plugin>  

No comments:

Post a Comment