|
From: Alex G. <ale...@ne...> - 2010-11-02 21:59:18
|
02.11.2010 18:38, Christian Blichmann kirjoitti:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> 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.
Works fine for me. Jython 2.5.x contains its own JSR-223 engine so don't
try to use the old engine jar with the new Jython. That leads to...well,
you already know ;)
> [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,
>
> - --
> Christian Blichmann
>
> ========================================================================
> zynamics GmbH - Address: Grosse Beckstrasse 3, 44787 Bochum, Germany
> - Phone: +49 (234) 6 87 07 86 - Fax: +49 (234) 57 00 02 00
> - UstId: DE814229418 - Trade Register: HRB 9626
> ========================================================================
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iQEcBAEBAgAGBQJM0D6eAAoJEOF0gv4uh+kfP9IH/AzhqpssyjnEnKE8wZlIeg07
> /0MmWLMFxaLaugypd01X/hEYMYP9OE1oK3IqOAeDhRzkktzZuImVa90+gfTXzXhT
> 3svAGOPlNhqs9I0V1O39/b/QSMfi4k7pkRYAuM8Ou70vWJunGnStoqMtvUrA3Tb8
> 0ho8LzBiRgBLsCI+WTF7J0zNg+qKzGF/UW6G8zoWIRLTNpGEDcboPnc1kZ7W7OY7
> Bk8VmHVCDkziSFdu3oGsY7D2ZqG36xrv80jHnXv0+6BSdvJ6XfRnPc/ZLefyt2pG
> uYvkjLDp7VWzyO6VSy1wFAQoybXsVupYQPGVk5UD4Y8+ShpAXCS3ew3YJcZAkNc=
> =xBNK
> -----END PGP SIGNATURE-----
>
> ------------------------------------------------------------------------------
> 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
|