Fork me on Github s

Posts Tagged jruby

Using Java classes in JRuby

I needed to do some reflection today so I fired up interactive JRuby (jirb) to inspect a jar.  Surprisingly, I couldn’t remember exactly how to use Java classes in JRuby.  So I did some searching on the internet and found this to be a common question with many answers.  So I figure I will document it here in case I forget how in the future.

Add it’s folder to the load path, require it, then use it!

$: << '/path/to/my/jars/'
require 'myjar'

# so we don't have to reference it absolutely every time (optional)
include Java::com.goodercode

my_object =

Tags: ,

1 Comment

JRuby 1.5 to provide native support for Ant

In case you haven’t heard, the next version of JRuby will provide native support for Ant.  Much like antwrap, you will be able to call ant tasks straight from Ruby.  There are some pretty good examples here, but no examples of how to get it running on your machine today.

  1. First, you will need to install Git SCM
  2. Next, create a directory, JRuby on your machine
  3. CD to that directory, and run ‘git init’
  4. Next, run ‘git pull git://’
  5. Once it has finished downloading, you can run ‘ant’ to build it
  6. Now, just use the executable jar under bin to run the latest version of JRuby

Now get started converting those nasty ant builds to rake.

Tags: , ,

No Comments