![](/img/trans.png)
[英]Is it possible to create Java classes from JRuby and use them in Java?
[英]Can a Ruby script in JRuby use my Java classes if I haven't shared them with it?
如果我有一個Ruby
腳本通過執行ScriptingContainer
的JRuby
在我Java
應用程序,是Ruby
腳本能夠訪問或利用我在定義的類的Java
應用程序,如果我沒有共享的腳本什么 ?
通過分享這是我的意思:
ruby = new ScriptingContainer(LocalVariableBehavior.PERSISTENT);
ruby.put("main", MyClass.class);
ruby.runScriptlet(readFile("Test.rb"));
如您所見,我正在與Ruby
腳本共享一個名為main的變量,其值為MyClass.class
。
如果我不共享任何內容 , Ruby
腳本是否仍然能夠在我的應用程序中使用MyClass
?
是的,根據我的回答 :如果MyClass
在你的類路徑/ $LOAD_PATH
,JRuby會在你java_import
時把它拿起來。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.