Setting up a Dropwizard + Gwt:SuperDevMode project on OS X using Eclipse, Maven and GitHub

Until now, I’ve been using Gwt on App Engine, developing alone and using an old version of Firefox so I could continue using Gwt’s dev-mode. I’ve never used Maven before and it’s about time I figured out Superdevmode. Dropwizard will hopefully act as a suitable replacement for App Engine.

Download Eclipse

I’ve been using the 64 bit version. I’m not sure of any reason to use 32 bit unless developing apps for 32 bit computers.

For now, get 4.3 (Kepler) because the Google Plugin for Eclipse hasn’t been updated for 4.4 yet.

There’s no installer, you just drag and drop the uncompressed archive into your Applications folder.

For security reasons, OS X will prevent you from running Eclipse until you right-click it and select Open and then dismiss the security warning.

Download GPE

As of 14 July 2014, Eclipse 4.4 has been released but the Google Plugin for Eclipse hasn’t been updated for it, so we’re using Eclipse 4.3 for now. (TBH, I’m not 100% sure GPE is even needed.)

In Eclipse, go to Help, Install New Software, paste in the following download site and select the Google Plugin for Eclipse. Don’t worry about the Gwt SDK as it’s not offering the latest version and Maven should take care of it anyway.

If you get the following error after restarting (probably a fresh install of OS X and Eclipse) you’ll need to download a newer JDK. 1.7 is ideal for this project.

Go through the normal install process and then go to Eclipse/Preferences, Java/Installed JREs, press Search and select Java SE 7. Press edit and copy the location of JRE home. Also in Eclipse/Preferences go to Java/Compiler and set Compiler compliance level to 1.7.

Maven

Maven is a collaboration tool so required libraries are downloaded from the same source and the same build procedure (i.e. tests & compilation) is followed by each member of the team. It centres around a file, pom.xml — the project object model. When a new library is needed in the project, one member updates the pom and when everyone pulls that commit, everyone is immediately using the new library from the correct source (You can browse the jars Maven has downloaded in ~/.m2/repository/). Maven also provides Archetypes which are basically templates for projects. Download the binary .tar.gz (same as zip but better compression) from: http://maven.apache.org/download.cgi

In Finder menu Go, Go to Folder… /usr/local and make a new folder “apache-maven” and extract the archive in here. You’ll need admin permission.

Open a Terminal window, type nano ~/.bash_profile to edit the Bash profile (think autoexec) and add the following:

GitHub

Download the GUI client, copy to Applications, run, enter your GitHub username and password, Install Command Line Tools when asked. It will ask you to install some XCode tools (small enough).

Your new repository should appear in the app and you can Clone To Computer, making sure to put it in your Eclipse workspace. Then in Eclipse, New/Project, General/Java Project, Next, put the same name as the git cloned project and it will immediately recognise it as a a Git project.

Also in the GUI app, under Settings, Ignored files, copy the contents of my .gitignore file (and change line 21 to match your own project name) so you don’t end up uploading loads of crap to GitHub.

Dropwizard

Once it’s working, we’ll change it so the REST application sits under server.com/api/* and the root server.com/ serves static files. Add a folder called gwt under src/main/resources where we’ll later configure the Gwt compiler to output to. Edit the main DropwizardApplication class so all our REST calls go to company.com/api/

It also needs to be added to the server profile so the compiler knows what your client .java files mean, but the javax.validation library Gwt provides clashes with the one that Dropwizard provides, so we exclude that:

<dependency>

<groupId>com.google.gwt</groupId>

<artifactId>gwt-user</artifactId>

<version>${gwt.version}</version>

<scope>provided</scope>

<exclusions>

<exclusion>

<artifactId>validation-api</artifactId>

<groupId>javax.validation</groupId>

</exclusion>

</exclusions>

</dependency>

You need an index.html page in your src/main/resources/gwt folder which will be served by Dropwizard and fetch Gwt’s compiled JavaScript. The key line in it is:

You need a ProjectName.gwt.xml in your project root package. This file tells the Gwt compiler which libraries to use, which packages contain code to be compiled and which class of yours contains the Entrypoint (Gwt’s public static void main(String[] args) ).

The entrypoint class is a bit long to go into here. It’s an edited version of the Google Plugin for Eclipse sample code except it’s using RequestBuilder to GET json from your Dropwizard app rather than using Gwt RPC.

To get all this running, compile the Gwt code using mvn package -P client then recompile the server side to include the newly created Gwt files with mvn package -P server and run the server again, but just visit http://localhost:8080/ this time.

Repackage client and server, run the server and in your project root folder run:

mvn gwt:run-codeserver -P client

The first time you run this, you’ll be told to visit the codeserver at http://localhost:9876/ to copy a bookmarklet to your bookmarks bar which you’ll then use to recompile the app after each small change.

More

What’s above should get you going but, as with any project, there’s bound to be more to configure.

When you begin testing, because the dependencies are split, you’ll have to configure Maven to only test the client code with the client dependencies, by putting this in the build/plugins section:

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven–surefire–plugin</artifactId>

<version>2.17</version>

<configuration>

<includes>

<include>**/Test/**/client/*</include>

</includes>

</configuration>

</plugin>

I’d like to have the run configurations set in Eclipse to possibly not need Terminal at all, but I haven’t looked into this at all yet.

Keep an eye on my actual project’s pom.xml which will be frequently updated (for a while!) and less likely to contain bugs.

Suggested edits to this blog are of course welcome! I’m no senior software developer yet, so appreciate any tips.

Post navigation

4 thoughts on “Setting up a Dropwizard + Gwt:SuperDevMode project on OS X using Eclipse, Maven and GitHub”

Hello Brian, thx for the great post! I just forked the project on github and tried but when starting the server gives me an error:
Exception in thread “main” java.lang.NoClassDefFoundError: javax/validation/ParameterNameProvider
at org.hibernate.validator.HibernateValidator.createGenericConfiguration
(HibernateValidator.java:41)…

I searched the dependencies and this class is not part of the validation-api-1.0.0.GA.jar.
Do you have a hint what’s missing or wrong with the pom?

Hey. I just pulled it again and it worked fairly easily. I had to compile the server first before the client would compile, then compile the server again to ensure the Gwt output was included to be served. Basically, all I did was:

For your problem, the Maven profiles in this project are just there because of this javax.validation clash. How are you starting the server? I’ll see if i can reproduce and understand it. But if you’re not using -P server/client when using Maven you’ll definitely run into problems — the exclusion on line 47 should ensure the correct version is used by the server.