[英]Can a Ruby script in JRuby use my Java classes if I haven't shared them with it?
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 ? 如果我有一个Ruby
脚本通过执行ScriptingContainer
的JRuby
在我Java
应用程序,是Ruby
脚本能够访问或利用我在定义的类的Java
应用程序,如果我没有共享的脚本什么 ?
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
. 如您所见,我正在与Ruby
脚本共享一个名为main的变量,其值为MyClass.class
。
If I don't share anything , is the Ruby
script still capable of using MyClass
in my application? 如果我不共享任何内容 , Ruby
脚本是否仍然能够在我的应用程序中使用MyClass
?
是的,根据我的回答 :如果MyClass
在你的类路径/ $LOAD_PATH
,JRuby会在你java_import
时把它拿起来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.