One of the main advantages of service engineering in Java is that there are quite a lot of environments, libraries, frameworks, IDEs and plugins to choose from. That’s also a major drawback. We ran into this while doing a recent prototyping project, and once again discovered the hard way that there is a certain threshold before you run into framework limbo, dependency hell and assorted related afflictions.
There is a saying in Dutch about donkeys and bumping into the same stone twice. Our new general rule of thumb is that you should use never use more than about two (plus or minus one) environments, libraries, frameworks, IDEs and / or plugins at once. Ever. You’ll save yourself from being a donkey by using only the stuff you really need. So read on if you want to risk countless hours of frustration with Eclipse, Maven Google Web Toolkit and Lombok.
Disclaimer: we have switched to using another GUI framework which is more suited to our needs.
Prerequisites: Environment, Reading and Configuration
Overview of environments, libraries, frameworks, IDEs and plugins used in this article:
- Oracle’s JDK 1.6 as the runtime environment
- Maven 3.0.4 as the build environment
- GWT 2.4.0 as the GUI framework
- Lombok 0.11.0 as a helper library for saving heaps of time writing code
- Eclipse 3.7 as IDE
- Google Eclipse Plugin (GPE) 2.5.2, with the following plugins:
First of all, credit where credit is due, so do some light reading to get you started:
- Lars Vogel’s excellent guide for including other project in an Eclipse GWT project.
- The main GPE issue that we kept running into and kept us from using Lombok in the end.
- GWT’s Serializable Type Guide. Read this to learn about what you can and can’t send over the line using GWT’s RPC mechanism.
- The GWT Wiki’s Working With Maven entry. Describes the steps of getting m2eclipse to play nice with GWT and Eclipse 3.7. When starting a new project based on the gwt-maven-plugin archetype, be sure to quick fix the lifecycle management errors and correct your POM to “execute” instead of “ignore” the execution steps, as listed in the comments below the entry.
Also, be sure to configure Eclipse to run in the 1.6 JDK (configure -VM in eclipse.ini to point to your javaw.exe in the JDK). We’ve had too many issues from using anything higher than a 1.6 JDK. Also make sure that you’ve set your JAVA_HOME environment variable to the correct path.
Eclipse Project Structure: Simple vs. GWT Projects
Let’s start off with the project structure. I’m not going to go in-depth on how to set this up, but you’d typically want to split your code into two or more Eclipse projects. One or more are fairly simple Maven-enabled projects which contain code you’d like to share with other projects, such as the project data model. The simple projects contain code annotated with Lombok annotations. The other is a Maven project based on the gwt-maven-plugin archetype. This project contains the GWT stuff and the web GUI.
Main Points of Attention: No Lombok, Source Available via Maven
Now that you have the project structure set up, there are two main points of attention.
Don’t use Lombok in the classes that GWT has to use. GWT will not be able to interpret Lombok-ed source code due to the bug outlined in the light reading section. This is a shame: Lombok saves you heaps of time coding getters, setters, delegates and other stuff you typically spend too much time on. So, for the non-GWT Eclipse projects, de-Lombok the classes that you want to serialize using GWT’s RPC mechanism. We did our de-Lombok manually after our data model was done, but we’ve also experimented with the Maven Lombok plugin to de-Lombok automatically. Go here if you’re interested.
For non-Eclipse projects:
- Include a module .gwt.xml in your simple projects for the classes that you’ll be using in GWT as outlined by the article in the light reading section
- Configure the POM to include source generation. This means configuring maven-source-pluginin the POM:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin>
For the GWT Eclipse project, include the correct Maven dependency on the simple projects. This means using the source classifier in the POM dependency description:
<dependency> <groupId>org.servicelab.myproject</groupId> <artifactId>myartifact</artifactId> <version>0.0.1-SNAPSHOT</version> <classifier>sources</classifier> <scope>provided</scope> <type>jar</type> </dependency>
It looks simple, but you will run into trouble. When you do:
- Delete your run configurations for GWT
- Clean your projects in Eclipse and do Maven->Updates
- Run mvn:clean and mvn:install for your simple project
- Be sure to set the debug level to “ALL” in your Eclipse run configuration to make sense of which classes don’t work in GWT.