possible to pass python objects into java without jython?

Steve Menard foo at bar.com
Tue Nov 9 21:48:28 EST 2004


Maurice Ling wrote:
> 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 passes a python object (pO) to pB. Now I 
> require pA to be called in a java class (jC) and pass pO into jC. As pA 
> uses non-python modules, I am not able to use Jython on this.
> 
> Are there any way out in this?
> 
> Thanks in advance.
> 
> Maurice

The simple answer is no. The complex answer is maybe, but not without 
some work on your part.

As part of JPype I made the opposite : allow Python to use Java classes. 
That was easy as python is very dynamic.

Going the other way around .... I don;t see how. The java part must want 
to receive a specific Java type. Even if that type is Object (the root 
of all object types in Java), tehre is no way for Python object to be 
one of those.

Case #1 : the "main" program is in Python, and the Java type to be 
received is a Java interface. In that specific case, JPype 
(http://jpype.sourceforge.net) can help you. You can "wrap" your pO into 
the correct Java type and apss it in.

Otherwise, as has been mantioned before, you will need some kind of 
remoting mechanism. Corba might provide a middle ground, or XML-RPC/SOAP.

Good luck.

Steve



More information about the Python-list mailing list