Google App Engine and Maven

I created a small project that I wanted to host somewhere for free. Amazon free tier or Google App Engine? I already have experience with AWS, so I decided to try GAE. It is completely different, of course. And it didn’t start quite well, with some NullPointerExceptions from the eclipse plugin. But ultimately, it worked fine. However, I was a bit confused how to use Maven in a GAE project. By default, everything should go to the /war directory, and that’s not maven’s directory structure. And this post scared me even more – the pom.xml looks appalling. What I ultimately achieved is workable, and the pom remains simple.

  • mavenzie your project (m2eclipse). Update project configuration to have everything in place
  • In right click > Properties > Google > Web applications have the path pointing to “target/project-0.0.1-SNAPSHOT” (or whatever your assembly folder is), and uncheck the “launch and deploy from this directory”.
  • Move everything from “war” to “src/main/webapp”. Parhaps without the jars, which you can add as maven dependencies
  • run maven > package, so that the target directory is populated
  • Right click > Deploy to Google App Engine – it will ask you for a directory the first time – choose “…/target/project-0.0.1-SNAPSHOT” again (this is absolute path). It will remember this decision, but don’t commit the .settings/com.google.gdt.eclipse.core.prefs, because it now contains an absolute path

That way everything works fine. Before each deploy you should make a maven build, but that’s not that bad (well, generally speaking, it is bad, but you don’t have hot-deploy here anyway. And my build is really quick. If I had a huge project with a very long build, I wouldn’t go for GAE, but that’s just my opinion)

2 thoughts on “Google App Engine and Maven”

  1. As the author of the post that “scared you”, I think I should say a few words. I definitely agree, the POM I’ve made is butt-ugly and hacky, but the good part is, that it works both ways. I’m able utilize the full power of Maven while still being capable of developing use Maven for deploying pretty smoothly in Eclipse. Most of that ugliness is anyways for creating proper Eclipse project files. As you mentioned they may contain some user specific information like full paths, so it makes no sense to put those to SCM.

    The proper way of solving the interoperability issues with Maven and Google Plugin for Eclipse would be a m2e extension (like the one for Android projects). Already twice I’ve started that project, just to realize that the complexity of Eclipse together with m2e and Maven is way too much for me to be even able to set up a trivial project! I feel like banging my head against the wall. So if you or anyone else have any tips, they’d be greatly appreciated.

    I’ve been more comfortable doing the deployment via the maven-gae-plugin instead of Eclipse. Just by typing mvn gae:deploy it does all the magic.

  2. Yes, perhaps I should’ve stated more clearly that my setup is suitable for simple projects, while as things grow, something better would be required. Like, what you said, the maven gae plugin (after all – only that way you can do deploys via a continuous integration engine).

    I didn’t go for your approach, because a simpler thing worked for my simple needs. And I think many projects using GAE are not too complex.

    The ultimate problem with GAE, and with GWT for that matter, is that they expect a specific project structure. And maven doesn’t like that, so “hacks” are to be made. If google engineers had thought a bit more about that, less hacky solutions would be used.

    Thanks for your input btw.

Leave a Reply

Your email address will not be published. Required fields are marked *