use of Java modules

L

Luis P. Mendes

Hi,

I have a Python program that needs to interact with Java as follows:

1- A website supplied me java code that is able to perform some web
services;
2- my Python program triggers some events;
3- I would like to use that java code when an event is triggered, instead of
having to recode everything in Python;
4- I know nothing about java, don't even know what .jar .class and .java
files are used for;
5- I've checked Jython.org but I don't know if it is what I was looking for,
because, preferably, I wouldn't like to have to learn Java;
6- Example: is it possible to import a java function such as connect() and
use it in my Python program directly using parameters like:
z1=value1
z2=value2
if TRUE:
connect(z1,z2) <-- java function with z1 and z2
7- is it possible to have, as other example:
var1, var2 = JAVA_FUNCTION(z1,z2)

So,my question are:
is Jython the way to do it? if not, how?
are there tutorials for extreme begginers in using another language in
Python?

Luis
 
J

Jeff Epler

If you use the Jython (www.jython.org) implementation of Python, you
can call to arbitrary java modules easily.

There have been various projects to let the C implementation of Python,
CPython, play with Java.
http://64.233.167.104/search?q=cache:UIcaceSHRgUJ:www.freenet.org.nz/python/spiro/&hl=en
http://jpype.sourceforge.net/
.. and probably others.

I don't have experience with any of these, I just know their names from
spending a long time in the Python community, as well as doing a little
bit of google searching before sending this post.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFBN2F3Jd01MZaTXX0RAuHCAJ0VrS+D+RCpGpHLqJ7ZT/PAt1I0CQCfdGxx
VX7OeDA5v+jTnpfweXT7iOc=
=15jW
-----END PGP SIGNATURE-----
 
L

Luis P. Mendes

Steve said:
There is Jython. This works well if you python code is compatible. This
means any python libraries you use must be jython-compatible. Also,
python-language-wise, jython is still arounf puthon 2.1 afaik.

Secondly, tehre is JPype ( http://jpype.sourceforge.net ). It still
alpha (and even that can be termed generous hehe). This is my prefered
option, since I am it's developper hehe. In theory it should eventually
allow you to use any Java class as though it were a python class.

Thirdly there is spiro (http://www.freenet.org.nz/python/spiro/) I have
no experience with it, but I know it bridges the Python and Java VM by
using CORBA.

Lastly there was JPI, a interface generator that would expose specific
java classes to python. the website seems to be down though ...

All these solutions have one thing in common though ... you will have to
learn a bit about java. No so much as to need to program in it, but
enough to set up environment and classpath, etc ...

If you decide to use JPype, you get support for free ;)

Hope this helps,

Steve


Hello Steve,

I must thank you for your answer, as well as Jeff.

JPype really seemed what I was looking for. Now that you've told me (in the
SourceForge.net forum) that it's available in Linux, I'll try hard to use
it. For sure, we'll keep in touch!

From all the three projects, JPype seems to me, at least, as the one where
I'd have to learn less about Java. Correct me if I'm wrong.

Luis
 
S

Steve Menard

Luis said:
Hi,

I have a Python program that needs to interact with Java as follows:

1- A website supplied me java code that is able to perform some web
services;
2- my Python program triggers some events;
3- I would like to use that java code when an event is triggered, instead of
having to recode everything in Python;
4- I know nothing about java, don't even know what .jar .class and .java
files are used for;
5- I've checked Jython.org but I don't know if it is what I was looking for,
because, preferably, I wouldn't like to have to learn Java;
6- Example: is it possible to import a java function such as connect() and
use it in my Python program directly using parameters like:
z1=value1
z2=value2
if TRUE:
connect(z1,z2) <-- java function with z1 and z2
7- is it possible to have, as other example:
var1, var2 = JAVA_FUNCTION(z1,z2)

So,my question are:
is Jython the way to do it? if not, how?
are there tutorials for extreme begginers in using another language in
Python?

Luis

There are actually many ways for python to use Java classes.

There is Jython. This works well if you python code is compatible. This
means any python libraries you use must be jython-compatible. Also,
python-language-wise, jython is still arounf puthon 2.1 afaik.

Secondly, tehre is JPype ( http://jpype.sourceforge.net ). It still
alpha (and even that can be termed generous hehe). This is my prefered
option, since I am it's developper hehe. In theory it should eventually
allow you to use any Java class as though it were a python class.

Thirdly there is spiro (http://www.freenet.org.nz/python/spiro/) I have
no experience with it, but I know it bridges the Python and Java VM by
using CORBA.

Lastly there was JPI, a interface generator that would expose specific
java classes to python. the website seems to be down though ...

All these solutions have one thing in common though ... you will have to
learn a bit about java. No so much as to need to program in it, but
enough to set up environment and classpath, etc ...

If you decide to use JPype, you get support for free ;)

Hope this helps,

Steve
 
S

Steve Menard

Luis said:
Steve Menard wrote:





Hello Steve,

I must thank you for your answer, as well as Jeff.

JPype really seemed what I was looking for. Now that you've told me (in the
SourceForge.net forum) that it's available in Linux, I'll try hard to use
it. For sure, we'll keep in touch!

From all the three projects, JPype seems to me, at least, as the one where
I'd have to learn less about Java. Correct me if I'm wrong.

Luis

humm that is actually hard to say ... Jython would probably require more
java knowledge. JPI and SPIRO I do not know enough about to say.

I forgot to mention an older project whose goal was very similar to
JPype. It is unmaintained but achieved greater featurefull-ness thaqn
JPype. It is JPE at http://jpe.sourceforge.net

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,206
Messages
2,571,069
Members
47,674
Latest member
scazeho

Latest Threads

Top