|
From: Alex G. <ale...@ne...> - 2010-11-02 21:46:26
|
02.11.2010 23:24, Roland Walter kirjoitti:
> Am 02.11.2010 18:08, schrieb Alex Grönholm:
>> 02.11.2010 18:38, Christian Blichmann kirjoitti:
>> Hi there,
>>
>> TL;DR: Calling methods from an embedded Jython script does nothing when
>> using JSR-223 and Jython 2.5.1, while Jython 2.2.1 just works fine.
>>
>>> Jython 2.5.1 has serious JSR-223 issues -- use 2.5.2rc2 instead. Come
>>> back here if it still doesn't work.
> You did not read the complete mail! He has just done this look further down!
Oops...sorry :(
I'll try running those and see if I can figure anything out.
>> [Disclaimer: This is my first post on this list, so please go easy on me
>> :-)]
>>
>> I'm currently trying to switch to Jython 2.5.1 from 2.2.1 and I'm having
>> a real hard time getting it to work...
>> Naively, I would've thought that replacing jython.jar with a new one
>> from 2.5.1 and removing jython-script.jar would just work.
>> I'm using the JSR-223 interface to embed the scripting engine. By
>> itself, everything seems to work as expected and the same way as in
>> Jython 2.2.1 (apart from the newer language that is).
>> The only thing that is not working for me is implementing a Java
>> interface from Python and calling methods on it. I have created a small
>> test program for this:
>>
>> ------------- myscript/ScriptingTest.java -------------
>> package myscript;
>>
>> import java.io.InputStream;
>> import java.io.InputStreamReader;
>>
>> import javax.script.ScriptEngine;
>> import javax.script.ScriptEngineManager;
>>
>> public class ScriptingTest {
>> public static void main(String[] args) {
>> try {
>> final ScriptEngineManager manager =
>> new ScriptEngineManager();
>> final ScriptEngine engine =
>> manager.getEngineByName("python");
>>
>> final InputStream is =
>> ScriptingTest.class.getResourceAsStream(
>> "/myscript/myscript.py");
>> engine.eval(new InputStreamReader(is));
>> } catch (final Exception e) {
>> e.printStackTrace();
>> }
>> }
>> }
>> ------------- myscript/PythonCallable.java -------------
>> package myscript;
>>
>> public interface PythonCallable {
>> String getAString();
>> void callAVoid();
>> }
>> ------------- myscript/myscript.py -------------
>> from myscript import PythonCallable as PythonCallable
>>
>> class MyPythonCallable(PythonCallable):
>> def getAString(self):
>> return 'A string'
>>
>> def callAVoid(self):
>> print 'Called a void method'
>>
>> print 'getAString() returns: %s' % \
>> MyPythonCallable().getAString()
>> print 'callAVoid():'
>> MyPythonCallable().callAVoid()
>> ------------------------------------------------
>>
>> Using Jython 2.2.1, I get:
>> $ java -cp .:jython.jar:jython-engine.jar myscript.ScriptingTest
>> getAString() returns: A string
>> callAVoid():
>> Called a void method
>>
>> This is just the way I would expect things to behave (OT: embedding
>> JavaScript and using a similiar script gives similiar output).
>>
>> Using a Jython 2.5.1 JAR, as created by the installer (with the default
>> options), I get this instead:
>> $ java -cp .:jython.jar myscript.ScriptingTest
>> getAString() returns: None
>> callAVoid():
>>
>> I also tried Jython 2.5.2 RC2 with the same result.
>>
>> If it matters: my environment is Debian Linux 5.0 AMD64 with the Sun
>> Java 1.6 JVM, Windows seems to behave the same way.
>>
>> Am I doing something fundamentally wrong? Is using JSR-223 this way
>> supported at all in Jython 2.5.1? If I missed relevant documentation,
>> can somebody point me in the right direction?
>>
>> Cheers,
>>
> ------------------------------------------------------------------------------
> Nokia and AT&T present the 2010 Calling All Innovators-North America contest
> Create new apps& games for the Nokia N8 for consumers in U.S. and Canada
> $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
> Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
> http://p.sf.net/sfu/nokia-dev2dev
> _______________________________________________
> Jython-users mailing list
> Jyt...@li...
> https://lists.sourceforge.net/lists/listinfo/jython-users
>
>> ------------------------------------------------------------------------------
>> Nokia and AT&T present the 2010 Calling All Innovators-North America contest
>> Create new apps& games for the Nokia N8 for consumers in U.S. and Canada
>> $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
>> Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
>> http://p.sf.net/sfu/nokia-dev2dev
>> _______________________________________________
>> Jython-users mailing list
>> Jyt...@li...
>> https://lists.sourceforge.net/lists/listinfo/jython-users
>
> ------------------------------------------------------------------------------
> Nokia and AT&T present the 2010 Calling All Innovators-North America contest
> Create new apps& games for the Nokia N8 for consumers in U.S. and Canada
> $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
> Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
> http://p.sf.net/sfu/nokia-dev2dev
> _______________________________________________
> Jython-users mailing list
> Jyt...@li...
> https://lists.sourceforge.net/lists/listinfo/jython-users
|