|
Re: [jruby-user] jruby inside jython: msg#00146lang.jruby.user
You are right. I got the same error when I tried your ruby script from Java program in which enough paths are set. I figured out the error was caused by JRuby script engine's incomplete initialization. After adding these three lines to the init() method of JRubyScriptEngine class, I could run your script and got outputs as expected. IAccessor d = new ValueAccessor(runtime.newString("<script>")); runtime.getGlobalVariables().define("$PROGRAM_NAME", d); runtime.getGlobalVariables().define("$0", d); This seems to be one of the missing initialization processes of JRuby's script engine. For example, referring $stdout also raises a similar exception. But, I've not yet figured out where other bugs come from. -Yoko On Nov 15, 2007 12:00 PM, adam goucher <adam_goucher@xxxxxxxxxxx> wrote: > > Hmm. I don't think that was the problem (or if it was, I havent got to the > part where it would manifest. I have the lib path specified in the classpath > and and I set it as a java runtime option to be doubly sure. > > rem classpath > set CLASSPATH=C:\temp\jpythonruby\jruby-1.0.2\lib\jruby.jar > set > CLASSPATH=%CLASSPATH%;C:\temp\jpythonruby\jsr223-engines\jruby-engine.jar > set CLASSPATH=%CLASSPATH%;C:\temp\jpythonruby\jruby-1.0.2\lib\ruby\1.8 > > "C:\Program Files\Java\jdk1.6.0_03\bin\java.exe" > -Dpython.home="C:\temp\jpythonruby\jython2.2b2" -classpath > "C:\temp\jpythonruby\jython2.2b2\jython.jar;%CLASSPATH%" > -Djruby.lib=C:\temp\jpythonruby\jruby-1.0.2\lib\ruby\1.8 > -Djruby.home=C:\temp\jpythonruby\jruby-1.0.2 org.python.util.jython %ARGS > > The exception also happens in one of the files brought into the mix via the > require which would imply that finding parts of the install is not a problem > > -adam > > > > > > I think the problem is your jython code doesn't set the path to Ruby > > scripts resides in test/unit directory. As for Java, setting a system > > property, "com.sun.script.jruby.loadpath," before getting a instance > > of JRuby's engine might resolve this kind of errors. > > > > String loadPath = > > "C:/temp/jpythonruby/jruby-1.0.2/lib/ruby/1.8"; > > System.setProperty("com.sun.script.jruby.loadpath", loadPath); > > ScriptEngineManager manager = new ScriptEngineManager(); > > ScriptEngine engine = manager.getEngineByName("jruby"); > > > > But, sorry, I don't know how to set a system property by jython. > > > > -Yoko > > > > On Nov 15, 2007 10:34 AM, adam goucher <adam_goucher@xxxxxxxxxxx> wrote: > > > > > > (I tried to search the archives, but it wasn't working...) > > > > > > I'm trying to use JRuby in Jython via the JSR-233 engine. The ruby > script > > > is a Test::Unit::TestCase originating one and runs from the command line > > > using the regular ruby interpreter. When I try to run it from it from > inside > > > my script however, things get ugly. I'm rather confused as to why it is > > > blowing up in the way it is, but realize that it might be something > trivial > > > to make it work and having hit the 'spent enough time not figuring it > out' > > > its off to the mailing list. > > > > > > So can anyone shed light into the origin of the backtrace or have solved > > > this problem a different way? > > > > > > Note: r.eval('puts "Hello!"') works fine, it is just when I pass in this > > > script that it does not work. > > > > > > Thanks. > > > > > > -adam > > > http://adam.goucher.ca > > > > > > <ruby> > > > require 'test/unit' > > > class ExampleTest < Test::Unit::TestCase > > > def test_something > > > p "ruby!" > > > end > > > def test_another > > > p "again!" > > > end > > > end > > > </ruby> > > > > > > <jython> > > > import javax.script.ScriptContext > > > import javax.script.ScriptEngine > > > import javax.script.ScriptEngineManager > > > import javax.script.ScriptException > > > > > > m = javax.script.ScriptEngineManager() > > > r = m.getEngineByName("jruby") > > > rs = open(f, "r") > > > y = r.eval(rs.read()) > > > rs.close() > > > </jython> > > > > > > <ugliness> > > > Traceback (innermost last): > > > File "jpythonruby.py", line 48, in ? > > > C:/temp/jpythonruby/jruby-1.0.2/lib/ruby/1.8/test/unit/autorunner.rb:59: > > > private > > > method `sub' called for nil:NilClass (NoMethodError) > > > from C:/temp/jpythonruby/jruby-1.0.2/lib/ruby/1.8/test/unit.rb:2:in > > > `call' > > > from > > > > C:/temp/jpythonruby/jruby-1.0.2/lib/ruby/1.8/test/unit/autorunner.rb:198:in > > > `run' > > > from > > > > C:/temp/jpythonruby/jruby-1.0.2/lib/ruby/1.8/test/unit/autorunner.rb:13:in > > > `run' > > > from C:/temp/jpythonruby/jruby-1.0.2/lib/ruby/1.8/test/unit.rb:278 > > > from <unknown>:1 > > > ...internal jruby stack elided... > > > from org.jruby.runtime.Block.yield(Block.java:260) > > > from org.jruby.runtime.Block.call(Block.java:214) > > > from org.jruby.RubyProc.call(RubyProc.java:169) > > > from org.jruby.RubyProc.call(RubyProc.java:148) > > > from org.jruby.Ruby.tearDown(Ruby.java:1447) > > > from > > > org.jruby.javasupport.JavaEmbedUtils.terminate(JavaEmbedUtils.java:66) > > > from > > > > com.sun.script.jruby.JRubyScriptEngine.evalNode(JRubyScriptEngine.java:396) > > > from > > > com.sun.script.jruby.JRubyScriptEngine.eval(JRubyScriptEngine.java:139) > > > from > > > javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:247) > > > from sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > > from > > > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) > > > from > > > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) > > > from java.lang.reflect.Method.invoke(Method.java:597) > > > from org.python.core.PyReflectedFunction.__call__(Unknown Source) > > > from org.python.core.PyMethod.__call__(Unknown Source) > > > from org.python.core.PyObject.__call__(Unknown Source) > > > from org.python.core.PyInstance.invoke(Unknown Source) > > > from org.python.pycode._pyx0.f$0(jpythonruby.py:48) > > > from org.python.pycode._pyx0.call_function(jpythonruby.py) > > > from org.python.core.PyTableCode.call(Unknown Source) > > > from org.python.core.PyCode.call(Unknown Source) > > > from org.python.core.Py.runCode(Unknown Source) > > > from org.python.core.__builtin__.execfile_flags(Unknown Source) > > > from org.python.util.PythonInterpreter.execfile(Unknown Source) > > > from org.python.util.jython.main(Unknown Source) > > > org.jruby.exceptions.RaiseException: org.jruby.exceptions.RaiseException > > > </ugliness> > > > > > > ________________________________ > > > Are you ready for Windows Live Messenger Beta 8.5 ? Get the latest for > free > > > today! > > > > --------------------------------------------------------------------- > > To unsubscribe from this list please visit: > > > > http://xircles.codehaus.org/manage_email > > > > > ________________________________ > R U Ready for Windows Live Messenger Beta 8.5? Try it today! --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: [jruby-user] Iterating over characters in a String ?: 00146, Gregory Murphy |
|---|---|
| Next by Date: | [jruby-user] jopenssl and ssh issue (was: ssh and sftp from JRuby?): 00146, Bill Dortch |
| Previous by Thread: | RE: [jruby-user] jruby inside jythoni: 00146, adam goucher |
| Next by Thread: | [jruby-user] Re: jirb and Netbeans Matisse: 00146, Tacio |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |