By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,275 Members | 1,745 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,275 IT Pros & Developers. It's quick & easy.

embedding jython in CPython...

P: n/a
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.
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
Jul 18 '05 #2

P: n/a
Thanks for the response. However, I continue to have problems. Allow me
to give some more detail.

For simplicity of testing, I hard coded the classpath and JVM path
(BTW getDefaultJVMPath() returns None on my system)

import os, os.path
from jpype import *

startJVM("C:/jdk1.5.0/jre/bin/client/jvm.dll",
"-Djava.class.path=D:/Temp/classes")
....
shutdownJVM()
I have setup a classes folder in the script folder (D:/Temp) and have
placed test.class in it.
I run the script from the script folder (working directory is the same
as script's root path in this case)

Now how do I load the class test? I am afraid I cannot make that out
from the docs.

The simple test class is
public class test
{
public int i = 100;
}
What do I have to do before I can write
test().i
?

Thank you for your time.

Jul 18 '05 #3

P: n/a
jo*******@rediffmail.com wrote:
Thanks for the response. However, I continue to have problems. Allow me
to give some more detail.

For simplicity of testing, I hard coded the classpath and JVM path
(BTW getDefaultJVMPath() returns None on my system)

import os, os.path
from jpype import *

startJVM("C:/jdk1.5.0/jre/bin/client/jvm.dll",
"-Djava.class.path=D:/Temp/classes")
...
shutdownJVM()
I have setup a classes folder in the script folder (D:/Temp) and have
placed test.class in it.
I run the script from the script folder (working directory is the same
as script's root path in this case)

Now how do I load the class test? I am afraid I cannot make that out
from the docs.

The simple test class is
public class test
{
public int i = 100;
}
What do I have to do before I can write
test().i
?

Thank you for your time.


About the getDefaultJVMPath(), could you send me your system
information? On windows, JPype uses the contents of the registry to find
the JVM. Of course, the usefulness of this mechanism is limited byt he
sample of configurations i can test (I have only one machine). So any
info you can provide me on yours can only help.

About the classpath. JPype 0.4 currently cannot import classes that are
in the "default" package. The fix is easy, simply put your "test" class
in a package. For exmaple, if you put the class in the package "test",
the code to load it would be :

test = jpype.JPackage("test").test
--
Steve Menard
--------------------
Maintainer of http://jpype.sourceforge.net
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.