Maven, Spring, Vaadin and Google AppEngine, Happy Together

happy_together

In true open source spirit, I scratched my itch. No, not that itch. If you complain about open source projects, you have all the tools at your disposal to fix the problem yourself. Last week, I posted that it’s not straightforward at all to make Spring, Google AppEngine (GAE) and Vaadin work together in Eclipse. This week, I present the solution.

Update: I’ve added a necessary repository to the pom file. So if you had problems previously, please download the file again. Your issues should be solved.

download the pom.xml

It’s a fairly long Maven pom.xml file, but I believe it remains understandable and usable. Using Maven also makes it easier to integrate your project in continuous build systems and to cooperate on a project with other people. The remainder of this post discusses the details, but you can just go ahead and download the pom.xml right away.

In order to get started you should:

  • Adjust the pom.xml to your liking. You probably want to change the artifact and group id’s.
  • Run “mvn clean” to create a clean project with the dependencies in the right location.
  • Run “mvn eclipse:eclipse” to generate the Eclipse configuration files.
  • Import the project into Eclipse (or you can use the m2eclipse Maven integration if you like)
  • Start programming your project. With this configuration you will be able to follow the Spring integration tutorial on the Vaadin site (including the annotation driven configuration, which is my favorite).

If you like to know a little more about what the pom.xml does, here are the various issues that are resolved by it.

Concord Jet
Creative Commons License photo credit: simononly

Google AppEngine

The main issue with Google AppEngine is managing the WAR structure. The Eclipse plugin for GAE cannot directly deploy a .WAR file and it needs a very rigid structure. It takes the contents of the “war” directory and deploys that. The exact directory cannot be changed, neither can the location of the dependencies. So the pom take care of:

  • Java classes are compiled to /war/WEB-INF/classes
  • JAR dependencies are managed in /war/WEB-INF/lib (“mvn clean” both deletes the old jar files and copies the new ones in the directory)

Eclipse project files

The second large block of code you’ll find in the pom.xml is setting up the Eclipse project files:

  • Configuring the various “natures” (those are the different plugins that are enabled for the project)
  • Setting up the environment with, for instance, some additional validators and builders.
  • For all of this to work, you will need to have all the corresponding Eclipse plugins installed (Vaadin plugin, Spring and AspectJ)

As always, this work would not have been possible without the help of a few people. I stand on the shoulders of giants.

There are still a few to-do’s left:

  • Google AppEngine has recently been update from version 1.3.0 to 1.3.1.
  • Maven support inside Eclipse is not yet enabled. I think adding the “org.maven.ide.eclipse.maven2Nature” nature to the pom.xml should solve this, but I haven’t tried it out yet.

download the pom.xml

Good luck and be sure to let me know if you encounter problems or have tips.

(image credit)

If you liked this, why not share it with your friends?
    This entry was posted in Java and JavaScript. Bookmark the permalink. Both comments and trackbacks are currently closed.

    12 Comments

    1. OneHP
      Posted February 16, 2010 at 8:03 pm | Permalink

      Hi,

      On mvn clean I'm getting this output…

      [INFO] ——————————————————
      [ERROR] BUILD ERROR
      [INFO] ——————————————————
      [INFO] Failed to resolve artifact.

      Missing:
      ———-
      1) com.google.appengine:appengine-api-1.0-labs:jar:1.3.0

      Try downloading the file manually from the project website.

      Tried bumping the version number up to 1.3.1 in the properties but that seems to make it worse (more errors).
      Any ideas? Want the full Maven output?

    2. Posted February 16, 2010 at 9:18 pm | Permalink

      It looks like there's a repository missing. I probably already downloaded the dependencies at some point. If you add the mvnsearch repo it should work:
      <repositories>
      <repository>
      <id>www.mvnsearch.org</id>
      <name>Maven search repository</name>
      <url>http://www.mvnsearch.org/maven2/</url>
      </repository>
      </repositories>

      I can't test it right now, but I'll try it out tomorrow and update the pom to reflect the change.

    3. OneHP
      Posted February 16, 2010 at 9:37 pm | Permalink

      That worked great thanks. Not got time to do the Vaadin tutorial at the moment but I'll let you know how it goes.

    4. Posted February 17, 2010 at 8:47 am | Permalink

      Great to hear it's working now. I have updated the downloadable pom file to reflect this change.

    5. Roger Parkinson
      Posted May 24, 2010 at 11:22 pm | Permalink

      In your earlier post on this when you introduced Maven it sounded like it was the only choice. There is also Ivy which plays well with Eclipse and Spring.

    6. Posted May 26, 2010 at 6:37 am | Permalink

      You're correct. Ivy is a great tool if you only want to do dependency management. You do have to combine it with some build toold (Ant, Gradle, maybe others). But I must confess its simplicity attracts me.

    7. Slscripters
      Posted July 6, 2010 at 3:30 pm | Permalink

      Hi, do you have a solution for developing vaadin + spring + maven + googleappengine without using eclipse?

    8. Dimitrisli
      Posted July 11, 2010 at 2:10 am | Permalink

      Great article, spot on what I was looking for!

      I have 'mvn clean' and 'mvn package' successfully from inside eclipse using m2eclipse. Now I am trying to run as a web application from the eclipse 'run configurations'. But I am getting the following:

      Exception in thread “main” java.lang.NoClassDefFoundError: com/google/appengine/tools/development/DevAppServerMain
      Caused by: java.lang.ClassNotFoundException: com.google.appengine.tools.development.DevAppServerMain
      at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

    9. Posted July 29, 2010 at 11:33 am | Permalink

      What's the main driver for using Maven here?

      If you're in Eclipse anyway what's wrong with simply using the GAE plugin to create your project. As for managing dependencies, you know what those dependencies are, so just download them and put the jars in the WEB-INF/lib folder.

      Maven just seems to add a lot of pain and fuzziness (to a lot of projects, not just this), so what am I missing?

    10. Asdf
      Posted July 31, 2010 at 3:01 pm | Permalink

      Obviously you can do everything by hand if you want to. You can hand-compile your project to java bytecode if you want.

      If maven was an absolute necessity, then it would be included in gae, but it's not. However, it adds many nice features including the ones mentioned in his post.

      I think this pom.xml is really nice and sweet. Thanks!

    11. Posted August 11, 2010 at 7:05 pm | Permalink

      In all honesty, I've been asking myself that same question. There is a lot of overhead associated with creating the Maven pom (but the maintenance is not that bad).
      There are a number of advantages: first it manages transitive dependencies, if I upgrade a library, I don't have to think about upgrading that libraries dependencies.
      Second, it's easy to have a portable project. If I want to involve other developers, I can just give them the project and they're good to go. It doesn't matter whether they use Eclipse or not.
      And finally, it creates a reproducible build, ideally suited for continuous builds and integration. Something which I'm not doing right now, but I envision I might at some point.
      But you're absolutely right when it comes to small, one-off projects, you might not want to bother and just go ahead and put everything in Eclipse.

    12. Posted August 26, 2010 at 12:11 pm | Permalink

      I pretty much agree with Peter’s reply: I want to have a repeateable & portable (not necessarily between IDEs but between developers ) build. I want to be able to build it externally using a CI tool (hudson FTW!) and possibly measure code metrics w/ Sonar.

      This said, I just threw out maven to move forward but I’m pretty sure I’ll regret it on the long run. I also think I’ll reconsider several times…

    7 Trackbacks

    1. [...] Update: If you want the full solution to this problem, please check this follow up post. [...]

    2. By 9 of my Best Posts On Java, a Streamhead Anthology on February 26, 2010 at 10:05 am

      [...] Using Maven to create a project with Spring, Vaadin and Google AppEngine. Not as easy as it might sound. [...]

    3. [...] a service in the Spring configuration and injecting it with the @Autowired annotation. With a little setup, this works perfectly in [...]

    4. [...] to World Domination By Peter Backx | Published: April 27, 2010 I’ve featured a number of Google projects before, most of them I liked. Some look strange and pointless. But I’ve always found the [...]

    5. By Launching my First Vaadin AppEngine Project on September 3, 2010 at 10:05 am

      [...] Integrating Maven, Spring, Vaadin and Google App Engine [...]

    6. [...] Then I enable dependecy management (Maven) on that project and it breaks.My pom.xml downloaded from Maven, Spring, Vaadin and Google AppEngine, Happy Together  1<project xmlns="http://maven.apache.org/POM/4.0.0&quot; [...]

    • Feedback or questions? Contact me right away.

      Comments have been disabled on my posts. Not because I don't want to hear from you, but because they were adding very little to the conversation (most of them were spam anyway). I do listen to you and try to keep as much posts as possible up-to-date and error free. So if you have a question, if something isn't working the way you hoped or you have general feedback, please use the contact form below. I guarantee an answer to every honest question or remark.
    • Get in touch
      1. (required)
      2. (valid email required)
       

      cforms contact form by delicious:days