473,372 Members | 953 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

embedding jython in CPython...

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
3 2272
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Michael Chermside | last post by:
Ype writes: > For the namespaces in Jython this 'Python internal thread safety' > is handled by the Java class: > > http://www.jython.org/docs/javadoc/org/python/core/PyStringMap.html > > which...
6
by: Dave Benjamin | last post by:
Hey good people, I've been doing a lot of simultaneous Jython and CPython programming lately, and just wanted to say, with no intended ill will toward any of the individuals who have been...
0
by: vincent Salaun | last post by:
hi all, here's my problem : I've embedded a python interpreter in our java application (based on the NetBeans palteforrm) using the Jython API : http://www.jython.org/docs/javadoc/index.html...
10
by: Randall Smith | last post by:
I would like to use a type 4 JDBC driver in my Python program. I believe I can use in with Jython. Do you know of some way to communicate between the Jython and Python processes so that the...
4
by: angel | last post by:
A java runtime environment includes jvm and java class (for example classes.zip in sun jre). Of course jython need jvm,but does it need java class. Thanx
5
by: Maurice Ling | last post by:
Hi, I have read that this had been asked before but there's no satisfactory replies then. I have a module (pA) written in python, which originally is called by another python module (pB), and...
1
by: Carl Waldbieser | last post by:
Has anyone had any experience embedding a CPython engine in a .NET application? In the COM/ActiveX world, it was pretty easy to use Mark Hammond's win32 modules to create a script engine component...
3
by: Gerard Flanagan | last post by:
Hello all I have a 'logger' module which is essentially just a facade over the 'logging' standard module. Can this be called from jython, and how is this acheived? This is a colleague's question...
2
by: Felipe De Bene | last post by:
Hi There, I'm trying to run an App I wrote in Python 2.5.2 in Jython 2.2.1 and everything works fine except when I try to import the Standard CPython's cookielib. I know this may sound stupid, I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.