HOW-TO: GAE + Eclipse + Maven

Help me in making the integration of GAE, Eclipse and Maven smoother and star this issue in AppEngine

Update: This solution doesn’t work on Eclipse 3.6 Helios and newest version of m2eclipse, check out the new solution if you’re on the latest version.

Nowadays everybody wants to manage their Java projects with Maven. And that’s totally sensible since Maven makes some things pretty damn easy, mostly because there’s a plugin for about everything. Yes, there is a plugin for Google App Engine (GAE) too, with which you can run the local development server and deploy your app. The same features are available on the Google Plugin for Eclipse, which is the Google preferred way to develop Java-based App Engine applications. So of course you’d like to also utilize the IDE integration, especially when the startup time of the local GAE development server is significally faster, thus increasing your productivity. So far, the problem has been, how to enjoy the benefits of both worlds, and I’ve have to tell you, it is now solved. Another thing I have to tell you is, how, so here we go.

Requirements

The integration isn’t compatible with m2eclipse, but it’s required for attaching the Maven war:exploded goal to Eclipse compilation. Also the integration is not perfectly production ready since it has to rely on snapshot version of maven-eclipse-plugin hosted at Bearded Geeks’ Maven repository. It’s required for linkedResource configuration and using the Eclipse Java Compiler. For more details see plugin’s issue tracker for linkedResources and output classes (Voting the issue and by other means trying to get the patches in highly appreciated).

So, I’ve converted the Guestbook Example into a Maven managed one and I’m distributing it as a Maven archetype. So, here’s how you begin:

mvn org.apache.maven.plugins:maven-archetype-plugin:2.0-alpha-4:generate \
  -DarchetypeGroupId=org.beardedgeeks \
  -DarchetypeArtifactId=gae-eclipse-maven-archetype \
  -DarchetypeVersion=1.1.2 \
  -DarchetypeRepository=http://beardedgeeks.googlecode.com/svn/repository/releases

By running that command you can create a Maven managed GAE app of your own. Just remember to change everything to match your application, like appId etc. To enable Eclipse integration run mvn eclipse:eclipse. After that you’ll need to import the project to Eclipse and after that and few project refreshs you should be fine (don’t mind it giving warnings about some missing libraries, they shouldn’t affect). Just run it as you usually run App Engine projects in Eclipse. Also on every Eclipse startup the Eclipse might put its GAE libraries back to war/WEB-INF/lib which’ll cause failure on startup, but cleaning the project solves the problem. You can also run your project using maven-gae-plugin by typing mvn gae:run on command line or deploy to App Engine by typing mvn gae:deploy.

If you’re not that into archetypes, you can find the project sources through SVN at Bearded Geeks’ Google Code project. The guestbook example can be found up and running at the project’s GAE page.

22 Responses to “HOW-TO: GAE + Eclipse + Maven”


  1. 1 heydiddy February 25, 2010 at 04:38

    Trying to follow this (bit of a maven newbie). Not sure what you mean by:

    > The integration isn’t compatible with m2eclipse, but it’s required for attaching the Maven war:exploded goal to Eclipse compilation.

    I installed the m2eclipse plugin (running gallileo) and cannot get around clean/build errors:

    Launch configuration type id “org.maven.ide.eclipse.Maven2BuilderConfigurationType” does not exist.
    Possible causes:
    Missing specification of a launch type (missing plug-in)
    Incorrect launch configuration XML

    Can’t find any clue on internet.

    • 2 hleinone February 25, 2010 at 10:05

      I think it means that the m2eclipse plugin is not properly installed. Check from: Help -> Install New Software -> Already Installed -> Features -> Feature Id: org.maven.ide.eclipse.feature -> Plug-in Details that there is Plug-in Id with org.maven.ide.eclipse.launching and of course that there’s no errors in the Maven plugins.

      I’ve tested this on 0.9.9 development version of m2eclipse, but it seems that there’s 0.10.0 out and the update site given above has become dysfunctional. I’ll check that out straight away and update the post afterwards.

      Note to others updating to 0.10.0 that it’s required to uninstall your 0.9.9 version before updating.

  2. 4 heydiddy February 25, 2010 at 05:02

    Gave up on eclipse. Running “mvn gae:run” from command line seems to cause the app to launch, but then get the following error with first hit:

    SEVERE: Error compiling file: …jsp//org/apache/jsp/guestbook_jsp.java

    [javac] class file for PersistenceManagerFactory not found
    [javac] PersistenceManager pm = PMF.get().getPersistenceManager();

    Would be very cool to get this going.

    • 5 hleinone February 25, 2010 at 15:57

      I have no idea about this. I can verify that the current version (just released a new one) works perfectly well in Maven, even on a clean environment. Just by running:

      mvn org.apache.maven.plugins:maven-archetype-plugin:2.0-alpha-4:generate \
        -DarchetypeGroupId=org.beardedgeeks \
        -DarchetypeArtifactId=gae-eclipse-maven-archetype \
        -DarchetypeVersion=1.1.2 \
        -DarchetypeRepository=http://beardedgeeks.googlecode.com/svn/repository/releases
      

      and after that in the created project’s directory:

      mvn gae:run -Dgae.home=/usr/local/lib/appengine-java-sdk-1.3.1/
      

      Replace the /usr/local/lib/appengine-java-sdk-1.3.1/ with whatever is the path to App Engine home directory in your environment.

      • 6 heydiddy February 25, 2010 at 17:54

        Lathered, rinsed, repeated and it worked this time (the persistence jars were not included correctly for some reason the first time). Thanks! Just need to get eclipse going now. Last time I worked with maven/eclipse a year ago it was ugly as well.

  3. 7 hleinone February 25, 2010 at 23:05

    I upgraded to 0.10.0 today and it works. Maybe you should check the log why the plugin doesn’t get installed.

    • 8 heydiddy February 26, 2010 at 00:56

      There was no dialog with error on install and could not find any logs in .eclipse nor workspace .metadata that mentions install errors.

      “Maven Integration for Eclipse” shows up as installed software, and there are the following jars under .eclipse plugins:
      ./org.maven.ide.eclipse_0.10.0.20100209-0800.jar
      ./org.maven.ide.eclipse.editor_0.10.0.20100209-0800.jar
      ./org.maven.ide.eclipse.editor.xml_0.10.0.20100209-0800.jar
      ./org.maven.ide.eclipse.jdt_0.10.0.20100209-0800.jar
      ./org.maven.ide.eclipse.launching_0.10.0.20100209-0800.jar
      ./org.maven.ide.eclipse.maven_model_edit_0.10.0.20100209-0800.jar
      ./org.maven.ide.eclipse.pr_0.10.0.20100209-0800.jar
      ./org.maven.ide.eclipse.refactoring_0.10.0.20100209-0800.jar

      but none of them contain a Maven2Builder* class (very suspicious).

      Anyway, don’t mean to waste your time on this. Thanks for the post.

      • 9 hleinone February 26, 2010 at 01:07

        Maven2BuilderConfigurationType seems to be mapped at ./org.maven.ide.eclipse.launching_0.10.0.20100209-0800.jar/plugin.xml to org.maven.ide.eclipse.internal.launch.MavenLaunchDelegate class which can be found in the same archive. So the problem must be a plugin installation failure. I’d suggest you to try installing the plugins to a fresh Eclipse installation.

  4. 10 Aaron Roller June 15, 2010 at 09:00

    Impressive! It worked just like you said without flaw. I even upgraded to 1.3.4 by changing the property gae.version and it all seemed to work fine inside of Eclipse.

    I switched over to the command line and ran a few commands. Upgraded the maven-gae-plugin version to 0.59 to match the latest and that all worked fine.

    Thanks for doing all this work. Looking at the pom this was no small feat and I don’t know that I could have gone forward with App Engine without both Maven and Eclipse…so I likely would have dove in the way you did. I’m glad I didn’t have to!

    Aaron

    • 11 hleinone June 15, 2010 at 11:54

      I’m glad that it works for you. I will upgrade the archetype to include the newest versions of both App Engine and the Maven plugin. Anyway, thanks for making my day!

  5. 12 Golf July 22, 2010 at 19:23

    I had the same problem using this,

    Launch configuration type id “org.maven.ide.eclipse.Maven2BuilderConfigurationType” does not exist.

    I fixed below line in launch file to solve the problem and it seems fixed, no more error messages.

  6. 16 Dieter Hubau February 23, 2011 at 20:14

    Thanks!

    I did everything like you explained and it’s working fine! I’m now working in Eclipse 3.6 (Helios) with latest version of Maven and GAE, Spring 3.5 and everything is running very smoothly!

    I’m currently running with a small .bat file which basically just sets my gae.home folder and runs mvn gae:run and i’m running with a similar file for deployments.

    Thank you for the great article!

    Keep it up ;)

  7. 17 Tim Hay May 27, 2011 at 02:32

    Hi all,

    we recently experienced this same issue when receiving am application developed by an external consultancy. The web application had been built using Maven 2.0.9 and Eclipse 3.4 or 3.5.
    We are using Springsource Tool Suite – based on Eclipse 3.6, and when we loaded up the (multi-module) project, we observed the following error:
    Launch configuration type id “org.maven.ide.eclipse.Maven2BuilderConfigurationType” does not exist.

    Now, the important thing is how to fix this. As Neil pointed out above, the maven external tool builder has been removed from the m2eclipse plugin, so the solution is to get down and dirty and edit the .project file(s).

    It will look something like this:

    tims-excellent-project

    org.eclipse.wst.common.project.facet.core.builder

    org.eclipse.jdt.core.javabuilder

    org.eclipse.wst.validation.validationbuilder

    org.maven.ide.eclipse.maven2Builder

    org.maven.ide.eclipse.maven2Nature
    org.eclipse.jem.workbench.JavaEMFNature
    org.eclipse.wst.common.modulecore.ModuleCoreNature
    org.eclipse.jdt.core.javanature
    org.eclipse.wst.common.project.facet.core.nature

    We found that removing the maven2Builder buildCommand element, as well as the maven2Nature element solved our problem. Save the file, reload your project, and the problem should go away.

    So for completeness, our .project file now looks like this:

    tims-excellent-project

    org.eclipse.wst.common.project.facet.core.builder

    org.eclipse.jdt.core.javabuilder

    org.eclipse.wst.validation.validationbuilder

    org.eclipse.jem.workbench.JavaEMFNature
    org.eclipse.wst.common.modulecore.ModuleCoreNature
    org.eclipse.jdt.core.javanature
    org.eclipse.wst.common.project.facet.core.nature


    Hope this helps!

    Cheers,

    Tim

    • 18 Tim Hay May 27, 2011 at 02:43

      OK, so the formatting of the above .project file contents isn’t brilliant. Many apologies, but I don’t know how to do it, and there doesn’t seem to be anything obvious. I tried surrounding it with code tags – to no avail. How did hleinone do it?
      If I do a Google search, all I get is information for blog writers on plugins – nothing for people leaving comments.

      Aaaarrrghrgrhhhh!

      • 19 hleinone May 27, 2011 at 03:00

        For me it looks fine with the <code> tags. If you want more fanciness, use the [sourcecode] tags. You should use them both like XML tags, so before your code snippet put [sourcecode] and after it [/sourcecode]. Like this:

        [sourcecode]
        if (tag == "sourcecode")
          look = nice;
        else
          look = buttUgly;
        [/sourcecode]
        

        Probably if you’d let the m2eclipse generate the project files again it wouldn’t generate those builders that no longer exist. If it still does, there has to be something in the POM telling it to do so. Same goes if you’re using mvn eclipse:eclipse for generating your Eclipse project files.


  1. 1 GAE + Eclipse + Maven – Update for Helios « Ham and Eggs Trackback on July 25, 2010 at 11:04
  2. 2 A tale of bits and bites » Blog Archive » m2eclipse + GAE in Eclipse 3.5 Trackback on January 20, 2011 at 11:49
  3. 3 FYI: Google App Engine and Maven in Eclipse : MHUs . DE Trackback on April 6, 2012 at 02:36

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s





Follow

Get every new post delivered to your Inbox.

%d bloggers like this: