[jruby] Access classes defined in a jar file, from within JRuby irb?

changepoint_advi.fischer at extaccount.com changepoint_advi.fischer at extaccount.com
Fri Aug 11 18:35:14 JST 2017


I have a jar file provided by someone else, no access to the source code. The jar file is in lib/other/appl.jar, the class is named Appl, and the package is com.abc.xyz

I would like to instantiate an Appl object from the JRuby irb, jirb_swing_ex.

(Of course my problem applies not only to jirb, but to running JRuby programs in general, but I explain it in the way I'm using it right now, just in case there are some peculiarities in Jirb which need special treatment).

THIS is the way it DOES work:

(1) Invoke jirb by:
java -jar jr/jruby-complete-1.7.27 jb/jirb_swing_ex

(2) Put the directory with the jar file into the load path:
$: << 'lib/other'

(3) Load the jar file
require 'appl.jar'

(4) Import the class
java_import com.abc.xyz.Appl

(5) Create the object
x = Appl.new

As I said, this works, and I can live with it if necessary, but I would prefer a simpler approach:

NOW TO MY QUESTION: Instead of fiddling around with load path and requiring the Jar, I thought I could let Java already include the jar file:

jar -cp lib/other/appl.jar -jar jr/jruby-complete-1.7.27 jb/jirb_swing_ex

The problem is: How can I get at my object? Doing just the java_import doesn't work, because the class name is not found.

So, what is the proper way to do it?



If you are not the addressee, please inform us immediately that you have received this e-mail by mistake, and delete it. We thank you for your support.



More information about the JRuby mailing list