danynl
danynl

Reputation: 299

Access java classes inside .jar in Jruby

I am currently developing my Jruby application which is contained inside a .jar file.

Within the jar, my file structure looks like this:

lib/launch.rb
lib/src/class1.rb
       /class2.rb
lib/com/class1.class
       /class2.class

Where 'class1.class' and 'class2.class' are compiled using jrubyc class1.rb and jrubyc class2.rb

I want to access these methods within 'class1.class' and 'class2.class' inside 'launch.rb'.

#launch.rb 

require 'java'
$CLASSPATH << "com" 
java_import 'class1'
java_import 'class2'

But, I am currently running into this issue :

NameError: cannot load Java class 'class1'

Is there another way to import and access these methods within class1 and class?

Upvotes: 1

Views: 294

Answers (1)

kares
kares

Reputation: 7181

com sounds like the package name, what you want is add lib to CP :

$CLASSPATH << File.expand_path('lib')
# now import the class with the full name (including package) :
java_import 'com.class1'
# ... or simply just :
Java::com.class1

but assuming its a (compiled) .rb script, maybe you just want to load it:

$LOAD_PATH << 'lib'
require 'class1'

Upvotes: 1

Related Questions