Integrating with Java inner classes?

Below is a simple script (using JRuby 1.1.4 on Win2K) that tries to use
the StringTemplate library JAR. Things work OK when trying to use Java
classes that don’t have inner classes…or partially implement Java

I’m rewarded with a ‘cannot link Java class
org.antlr.stringtemplate.StringTemplate’ exception when trying to use
the Java class StringTemplate that has 2 final static inner classes.

There’s a decent chance I missed some bit-o-info on the wiki site, but
what am I not getting?

Thanks, Jon


raise LoadError, ‘missing JRuby’ unless RUBY_PLATFORM == ‘java’
require ‘java’
require ‘D:/Jon/My Documents/JavaDev/antlr/lib/stringtemplate-3.2.jar’
rescue LoadError => e
puts “#{e.message}; exiting…”
exit -1

this causes a NameError saying cannot link the class.

error thrown from


in ‘method_missing’

#import org.antlr.stringtemplate.StringTemplate

why is there nothing in the STModule.constants array after this?

module STModule
include_package org.antlr.stringtemplate

but there’s a Java::OrgAntlr and Java::OrgAntlrStringtemplate?

if Java.constants.index(‘OrgAntlrStringtemplate’)
ST = Java::OrgAntlrStringtemplate

# can use a class that doesn’t have inner classes
aiw =
Java::JavaLang::System.out)) # yuck!
puts “Indentation = #{aiw.get_indentation_width}”

# can partially implement a Java interface in a Ruby class
class MyListener
  include ST::StringTemplateErrorListener
  def warning(msg)
    puts msg
end '[WARNING] just testing...'

# but can't seem to use a class with inner classes :(
st = 'Hello $name$ from StringTemplate!'
st.set_attribute 'name', 'Someone'

rescue Exception => e
puts e.message


To unsubscribe from this list, please visit: