1

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?

1 Answer 1

1

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'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.