Oct 19, 2008 0
Mixing Maven and Warbler
I have recently been working on mixing together a Ruby on Rails application with an Enterprise app. Initially I was looking into doing it with Goldspike, however after picking up that it was going out of fashion and being replaced with Warbler I decided to use that. I couldn’t find any clear documentation on setting up Warbler with Maven (while Goldspike came with a plugin) - so I decided to try and pull it together so that I could incorporate the Rails app into a larger Java product.
First of all I wanted to put my Rails application into a Maven like directory structure so I created /src/main/rails and put the app in there, then I knocked up a pretty standard POM for a WAR file. Next up I wanted to Warble the project so I first up I installed the gem.
pdodds:(svn)trunk[trunk:4184]/src/main/rails$ sudo gem install warbler Bulk updating Gem source index for: http://gems.rubyforge.org Successfully installed warbler-0.9.11 1 gem installed Installing ri documentation for warbler-0.9.11... Installing RDoc documentation for warbler-0.9.11... pdodds:(svn)trunk[trunk:4184]/src/main/rails$
Then I pluginize the Warble so that it will be available in my project using warble pluginize.
Next up I wanted to get my Maven pom sorted out - the quickest way I could find to get Warble integrated was through the jruby-rake-plugin. Adding the following plugin to my pom.xml ensures that the gems that I need are installed by the jruby plugin and then warble can be called in the compile phase.
<plugin>
<groupId>org.jruby.plugins</groupId>
<artifactId>jruby-rake-plugin</artifactId>
<version>1.1.4</version>
<executions>
<execution>
<id>install-gems</id>
<phase>process-resources</phase>
<goals>
<goal>install-gems</goal>
</goals>
<configuration>
<gems>warbler,rails</gems>
</configuration>
</execution>
<execution>
<id>build-war</id>
<phase>compile</phase>
<goals>
<goal>rake</goal>
</goals>
<configuration>
<launchDirectory>${basedir}/src/main/rails
</launchDirectory>
<args>war:clean war</args>
</configuration>
</execution>
</executions>
</plugin>
In the first instance of the execution of the jruby plugin we pull down and install the gems that we are going to use, in the second we actually call the Warble goals in the project to create the WAR file.
In order to quickly integrate this process with the standard WAR building in Maven we need to configure the Maven WAR plugin, you could also change the Warble output but in the end I found this way worked when I wanted to use the Jetty plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webappDirectory>${basedir}/src/main/rails/tmp</webappDirectory>
</configuration>
</plugin>
While this is pretty brief hopefully it helps others get going and I’m very open to alternate or better ways to achieve the same goal.








