JRuby 1.5 Integrates Maven and Ant

DZone 's Guide to

JRuby 1.5 Integrates Maven and Ant

· Java Zone ·
Free Resource
The JVM flavor of Ruby is rolling out version 1.5 today with integrations that transfer some of the build and config mojo from the Java platform to Ruby.  Java developers will also find the JRuby language to be more friendly in this release.  The new features that really stand out in 1.5 include Maven and Ant integration, and better Windows support; but first let's look at some JRuby 1.5 tips contributed to DZone by Vladimir Sizikov, a JRuby core contributor.

To find out how fast or slow JRuby 1.5 is loading Gems or libraries, run this script:
jruby -b -J-Djruby.debug.loadService.timing=true -e "require 'rubygems'"
You'll get output like this:
#>jruby -b -J-Djruby.debug.loadService.timing=true script\server
-> builtin/core_ext/symbol
<- builtin/core_ext/symbol - 35ms
-> enumerator
<- enumerator - 6ms
-> D:/work/jruby-dev/rails/xxx/config/boot
-> rubygems
-> rubygems/defaults
<- rubygems/defaults - 5ms
-> thread
<- thread - 7ms
-> etc
<- etc - 5ms
-> rbconfig
<- rbconfig - 7ms
-> rubygems/exceptions
<- rubygems/exceptions - 5ms
-> rubygems/version
-> rubygems/requirement
<- rubygems/requirement - 6ms

Next, if you want to find out what libraries JRuby requires or where it loads them, you can run this:
jruby -J-Djruby.debug.loadService=true -e "require 'yaml'"
and get output like this:
jruby -J-Djruby.debug.loadService=true -e "require 'yaml'"

LoadService: trying builtinLib: builtin/core_ext/symbol.class
LoadService: trying builtinLib: builtin/core_ext/symbol.rb
LoadService: trying resourceFromLoadPath: D:/work/jruby-dev/jruby/lib/ruby/site_ruby/1.8/builtin/core_ext/symbol.class
LoadService: trying resourceFromLoadPath: D:/work/jruby-dev/jruby/lib/ruby/site_ruby/1.8/builtin/core_ext/symbol.rb
LoadService: trying resourceFromLoadPath: D:/work/jruby-dev/jruby/lib/ruby/site_ruby/shared/builtin/core_ext/symbol.class
LoadService: trying resourceFromLoadPath: D:/work/jruby-dev/jruby/lib/ruby/site_ruby/shared/builtin/core_ext/symbol.rb
LoadService: found: file:/D:/work/jruby-dev/jruby/lib/ruby/site_ruby/shared/builtin/core_ext/symbol.rb
LoadService: trying builtinLib: enumerator.class
LoadService: trying builtinLib: enumerator.rb
LoadService: trying resourceFromLoadPath: D:/work/jruby-dev/jruby/lib/ruby/site_ruby/1.8/enumerator.class
LoadService: trying resourceFromLoadPath: D:/work/jruby-dev/jruby/lib/ruby/site_ruby/1.8/enumerator.rb

Also, if you're having any issues when launching JRuby on Windows, you can try running jruby.exe -Xtrace output.log and look at the extensive log output in the output.log file.

Ant and Rake
While JRuby 1.5 has implemented tighter integration with Apache Ant, the JRuby developers have also developed a seamless, two-way integration between Rake and Ant.  This basically means you can mix and match the tools in the same project.  Java developers who struggle with Ant's minimal support for imperative programming constructs will perhaps find comfort in Rake's cleaner syntax and full imperative programming environment.   

Ruby developers using Rake will find the Ant integration to be helpful for performing common Java tasks since Rake doesn't have many standardized cross-platform tasks like Ant.  Ant will also create build.xml files so that you can use software like NetBeans, which needs such a file.  You can essentially harness the strengths of each tool.  In Rake, Ant can be invoked and Ant targets can be called as Rake tasks.  Importing an Ant buildfile makes its targets available to Rake as tasks, allowing Rake users to interact with Ant buildfiles and their dependent systems.

Here's a blog post showing how to use Apache Ivy with JRuby 1.5's Ant integration.

With some help from Sonatype, JRuby 1.5 has achieved full RubyGems integration with every single Maven artifact.  Users of JRuby 1.5 will get access to around 60k additional libraries with this new feature.  Any Java library ever published into the public Maven repository can be installed as Gems (or used for dependencies) in JRuby 1.5.

The JRuby team pulled this off with Sonatype by creating a Maven server that looks like a standard Gem repository to JRuby.  With this change, many Java libraries are as easy to use as Ruby libraries in JRuby.  As companies continue to use JRuby for retail websites and airline refueling applications, the language will become increasingly lucrative to enterprise developers.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}