Using Java classes in JRuby
        Posted  
        
            by kerry
        on Gooder Code
        
        See other posts from Gooder Code
        
            or by kerry
        
        
        
        Published on Fri, 19 Nov 2010 21:17:31 +0000
        Indexed on 
            2010/12/06
            16:59 UTC
        
        
        Read the original article
        Hit count: 430
        
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 = SomeClass.new
© Gooder Code or respective owner