embedding jython in CPython...

Steve Menard foo at bar.com
Sat Jan 22 13:39:01 EST 2005


Jim Hargrave wrote:
> I've read that it is possible to compile jython to native code using 
> GCJ. PyLucene uses this approach, they then use SWIG to create a Python 
> wrapper around the natively compiled (java) Lucene. Has this been done 
> before for with jython?
> 
> Another approach would be to use JPype to call the jython jar directly.
> 
> My goal is to be able to script Java code using Jython - but with the 
> twist of using Cpython as a glue layer. This would allow mixing of Java 
> and non-Java resources - but stil do it all in Python (Jython and Cpython).
> 
> I'd appreciate any pointers to this topic and pros/cons of the various 
> methods.
> 
> 

Well now that IS getting kinda complicated ...

AS far a natively compiling Jython scripts ... well, if you natively 
compile them, it'll hard to "script" you java code afterward (I assume 
by scripting you mean loading scripts at runtime that were not know at 
compile time).

As for using JPype ... well it depends on what you want to script. if 
you Java code is the main app, I'd eschew CPython completely and use 
Jython to script. If you main app is in Python, and the Java code is 
"simply" libraries you wish to use, then I'f go with CPython + Jpype. It 
is very easy to manipulate Java objects that way, even to receive callbacks.

I guess it all comes down to what you mean by scripting, and exaclt what 
the structure of your application (as far as what is java and non-java). 
If you care to explain your situation a bit more, we'll be better able 
to help you.

Steve Menard
Maintainer of http://jpype.sourceforge.net



More information about the Python-list mailing list