简体   繁体   English

JRuby中的Ruby脚本是否可以使用我的Java类,如果我没有与它共享它们?

[英]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脚本通过执行ScriptingContainerJRuby在我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.

相关问题 是否可以从JRuby创建Java类并在Java中使用它们? - Is it possible to create Java classes from JRuby and use them in Java? 我有一个 Selenium 脚本和 GUI。 如果我的团队尚未下载 Selenium,我如何与他们分享 - I have a Selenium script and GUI. How can I share with my team if they haven't downloaded Selenium Eclipse找不到我已安装的Ruby gem(JRuby) - Eclipse can't find my installed Ruby gems (JRuby) 在Java EE项目中,删除类后,我无法找回它们吗? - In a Java EE project, after deleting my classes, I can't get them back? 为什么JRuby在重载时不能使用参数为RubyArray的Java方法? - Why can't JRuby use my Java method whose parameter is a RubyArray when it is overloaded? 如何在jruby中使用java.util.properties? - How can I use java.util.properties in jruby? 我可以在同一个项目中使用JRuby on Rails和Java Servlet吗? - Can I use JRuby on Rails and Java Servlet in a same project? 为生成的类添加@XmlRootElement注释后,我无法在源类中访问它们 - After adding @XmlRootElement annotation for generated classes i can't access them in my source classes 当你在嵌入式JRuby中执行Ruby脚本时,你能使用gems吗? - Can you use gems, when you execute a Ruby script in embedded JRuby? Java抱怨我还没有实现一个方法 - Java complains I haven't implemented a method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM