Accessing jruby script top-level environment variables from Java
j ruby 1.7. 23 (1.9.3p551) 2015-11-24 Java hotspot (TM) 1.7 on 64 bit server virtual machine 0_ 79-b15 jit [Windows 7-amd64]
I run a scriptlet in my script container as follows:
(RubyObject) ro = (RubyObject)container.runScriptlet(org.jruby.embed.PathType.RELATIVE,"example.rb");
Where the container type is scriptingcontainer Set local variable behavior to transient
File example RB contains the following lines:
foo='xxx' $bar='yyy' 'zzz'
I can retrieve the value 'zzz' from the Java side because it is explicitly returned from the runscriptlet I can also retrieve the value of $bar
container.get("$bar")
Is there any way to retrieve the value of foo? container. Get ("foo") returns a null pointer
I also tried to change the local variable behavior to "persistent", but the result was the same
Solution
I think you have used the scriptingcontainer (localvariablebehavior. Persistent), but this necessity means that you can access most of the contents of the scriptcontainer Maybe we can modify your code and try parse See example 4 It may inspire you I hope this will help