TvE 2100

At 2100 feet above Santa Barbara

Accessing Inner Java Classes via Rjb

The entry below is copied straight from another blog. I ran into the problem described therein a few minutes ago and found this solution via Google’s cache. The origin server doesn’t respond, so who knows, this may be lost as soon as it pops out of the cache, so I am duplicating it here. I also can’t tell who wrote it, just that it came from So here we go:

== RubyJavaBridge is nice == Sunday, February 12th, 2006

I’ve been playing with the RubyJavaBridge that was talked up at the last Ruby get-together and so far it is indeed very swank.

I couldn’t resist investigating the issue Les had with accessing static inners and I think I found the syntax. Accessing inner classes (static or not) can look a little wonky but it is doable. Statics are loaded like any other class, but their pathname is ‘OuterClass$StaticInnerClass’. The nonstatic inner classes are a tiny bit trickier. Import like the static, with ‘OuterClass$Inner’; now you have the inner class, but the trick is in instantiating an instance: you must provide an OuterClass instance as the first argument to the constructor (thus revealing a little behind the curtain of java the implicit access an inner has to its outer’s methods and data):

Outer = Rjb::import(‘Outer’)
Inner = Rjb::import(‘Outer$Inner’)
StaticInner = Rjb::import(‘Outer$StaticInner’)

outer =
inner =
staticInner =

I have full sources and the example output below.

I have so many ways I want to use this bridge. This is the key I need to access the AS400 from Ruby. Tasty tasty.

[Sorry, the “full sources and examples” are not in the Google cache…]