use of Java modules

Steve Menard foo at bar.com
Sat Sep 4 00:57:10 CEST 2004


Luis P. Mendes wrote:
> 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






More information about the Python-list mailing list