1

If I have a Ruby script executed by ScriptingContainer of JRuby in my Java application, is the Ruby script capable of accessing or making use of a class I have defined in my Java application if I haven't shared anything with the script?

By sharing this is what I mean:

ruby = new ScriptingContainer(LocalVariableBehavior.PERSISTENT);
ruby.put("main", MyClass.class);
ruby.runScriptlet(readFile("Test.rb"));

As you can see, I am sharing with the Ruby script a variable called main, whose value is MyClass.class.

If I don't share anything, is the Ruby script still capable of using MyClass in my application?

1 Answer 1

3

Yes, as per my answer there: if MyClass is on your classpath/$LOAD_PATH, JRuby will pick it up when you java_import it.

Sign up to request clarification or add additional context in comments.

4 Comments

Ah, and it can't be avoided?
@Omega What do you want to avoid? Putting the class on the classpath?
That despite having the classes on the classpath, avoid the java_import.
You must either use the Java:: prefix or java_import as your class is in the "default" package, or put your class in a package that starts with either org or com and then refer to the class with its fully-qualified name.

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.