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.

about me

Welcome to the my personal blog, I'm Philip Dodds and I am a Brit living in the US. I have been working in technology for about 15 years and been through a range of worlds from media to banks to open source. Still deep down I love to code and I'm a total geek. I enjoy seeing the world, good food, good bars and seeing my son.

pictures

IMG_0094.JPGJack on his iPhoneJack and his vacuum cleanerMoving the furniture aroundThe new Cars punch bagGetting ready for the traveling life

twitter

  • Back in London. Home again after 3 years. Too long 13 hrs ago
  • RT @BarCampCLT: We are looking for sponsors - help create the first Barcamp in Charlotte - contact philip.dodds at me.com 18 hrs ago
  • pondering whether Picasa and iPhoto compliment each other ? 19 hrs ago
  • looking forward to getting to London this afternoon - anyone recommend a good pub in the City? its been a while 19 hrs ago
  • last chance to see some family for a while - and thinking I might get out to Sydney before the end of 2009 19 hrs ago
  • More updates...

Powered by Twitter Tools.