Jetty and the Yeoman Maven Plugin

Everyone knows productivity is important. For me, anything that can be automated in my development lifecycle is a major win for me. Recently, I’ve been focusing a lot of my development energy on JavaScript and client side development. One particular framework I’m really interested in is AngularJS. I won’t go into details about it in this post, that’s not my goal of this post.

As I started exploring AngularJS, I came across Yeoman which is a tool for rapidly scaffolding out an application. I played with it for a while and was instantly hooked by the evident productivity gains I could achieve. With the aid of a few other tools, Yeoman creates a nice workflow for writing web apps that perform well. You get minified CSS and JavaScript for your app, so the server requests are fewer and quicker. This is achieved with Grunt which is the build tool for your app. Another tool called Bower takes care of third party package management, similar to Maven in the Java world.

All that productivity is great, but I want more. I found the yeoman-maven-plugin. This plugin has proven very useful in my development. Essentially, instead of running the grunt command from the command line, this plugin does that for you during your Maven build while ensuring bower gets all the needed dependencies. With a little configuration, this plugin becomes an integral part of building a webapp with Maven and utilizing Yeoman without much additional effort.

Setting up The Jetty Maven plugin

Now that we’ve got the Yeoman Maven plugin setup, lets look at setting up the Jetty Maven plugin to work with our new directory structure. I really like using Jetty in development because its quick. The problem I ran into though is that simply using “jetty:run” doesn’t work with our Yeomanified app. Jetty doesn’t know about the yo/dist directory created by Yeoman. This is actually pretty easy to accomplish once I figured it out. Here’s the plugin config in my pom.xml.

                    <baseResource implementation="org.eclipse.jetty.util.resource.ResourceCollection">

With the above Jetty Maven plugin config, now running “jetty:run” will tell Jetty to also look in yo/dist for web resources.


Please visit the Yeoman Maven plugin page on Github for setup instructions.

If you can read French, the plugin’s author Thomas posted a great post to.

While developing from IntelliJ on my Mac, I had the issue of npm, yeoman, grunt and bower not being found by Maven. The Yeoman plugin’s author pointed out that these tools weren’t on my PATH variable. Once fixed, the tools worked fine when Maven ran inside IntelliJ. You can refer to my Stackoverflow post for the answer from Thomas ;)

About these ads


Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s