468,290 Members | 2,025 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,290 developers. It's quick & easy.

Python and Java

Suppose you have an application written in Java, and you want to enable
other applications or processes written in Python to communicate with
it, i.e., to use Python as a scripting language for the application.
On Windows you could do this with COM and various addons such as
J-Integra and Mark Hammond's libraries.

How would you do this if you want a mechanism that is portable across
Windows, Linux, Mac, and Unix?

Any ideas? Jython would be a natural candidate, but it is stuck at
Python 2.1 and seems to have an uncertain future.

Thanks in advance.

Mar 6 '06 #1
6 1384
"JKPeck" <JK****@gmail.com> writes:
Suppose you have an application written in Java, and you want to enable
other applications or processes written in Python to communicate with
it, i.e., to use Python as a scripting language for the application.
On Windows you could do this with COM and various addons such as
J-Integra and Mark Hammond's libraries.

How would you do this if you want a mechanism that is portable across
Windows, Linux, Mac, and Unix?


I suppose you could make some layer that sits between JNI and Python's
C API. It may be easier to use some slower IPC mechanism like
sockets, if you can tolerate that.
Mar 6 '06 #2
JKPeck wrote:
Suppose you have an application written in Java, and you want to enable
other applications or processes written in Python to communicate with
it, i.e., to use Python as a scripting language for the application.
On Windows you could do this with COM and various addons such as
J-Integra and Mark Hammond's libraries.

How would you do this if you want a mechanism that is portable across
Windows, Linux, Mac, and Unix?

Any ideas? Jython would be a natural candidate, but it is stuck at
Python 2.1 and seems to have an uncertain future.


Jython 2.1 works great and there is (slow) progress being made in
modernizing it. I recommend it.

Kent
Mar 7 '06 #3
For most purposes Jython 2.1 is just fine. The lack of recent features
is not a show stopper. What do you need metaclasses? decorators? BTW,
there is Jython 2.2 as an alpha release.

There are a number of ways you can use Java code through Python.

Use JPype to start a Java VM
http://jpype.sourceforge.net/

Or compile using GCJ and expose as a DLL/SO or better yet, make a SWIG
extension.
A good example for this is PyLucene.
Python/Java Wrapper Generator
http://www.rexx.com/~dkuhlman/generate_wrappers.html
simplifies the process.

Or use some standard interop mechanism. Write an XMLRPC/SOAP/CORBA and
script via Python. This is similar to the COM approach.

Or maybe, you can look into XPCOM. I have no experience with it.

And finally a bit more perverse approach that I used once. Converted
Java bytecode to CIL with IKVM.
http://www.ikvm.net/
And then I used Python for .NET
(http://www.zope.org/Members/Brian/PythonNet), a really well
implemented integration module if I ever saw one, to access the code.

Mar 7 '06 #4
Thanks for these suggestions. To be clear, we already have a Python
2.4 minimum requirement for other reasons, and we are looking for a
long-term solution so that as Python advances, the scripting solution
can keep up in a timely way.

Since the Java code is for a very large, complex application, we need
to bring Python to Java rather than Java to Python.

We will take a look at some of the other ideas.

Mar 7 '06 #5
JKPeck wrote:
Suppose you have an application written in Java, and you want to enable
other applications or processes written in Python to communicate with
it, i.e., to use Python as a scripting language for the application.
On Windows you could do this with COM and various addons such as
J-Integra and Mark Hammond's libraries.

How would you do this if you want a mechanism that is portable across
Windows, Linux, Mac, and Unix?

Any ideas? Jython would be a natural candidate, but it is stuck at
Python 2.1 and seems to have an uncertain future.


JPype or CORBA/ICE.

Diez
Mar 7 '06 #6
"JKPeck" <JK****@gmail.com> writes:
Suppose you have an application written in Java, and you want to enable
other applications or processes written in Python to communicate with
it, i.e., to use Python as a scripting language for the application.
On Windows you could do this with COM and various addons such as
J-Integra and Mark Hammond's libraries.

How would you do this if you want a mechanism that is portable across
Windows, Linux, Mac, and Unix?

Any ideas? Jython would be a natural candidate, but it is stuck at
Python 2.1 and seems to have an uncertain future.

Thanks in advance.


If you need real CPython (e.g., need add-on libraries compiled in C),
then XMLRPC is a clean way to make the connection.
Mar 7 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Dave Brueck | last post: by
1 post views Thread by bezeee | last post: by
14 posts views Thread by Wolfgang Keller | last post: by
114 posts views Thread by Maurice LING | last post: by
2 posts views Thread by Hal Vaughan | last post: by
30 posts views Thread by Stuart Turner | last post: by
25 posts views Thread by abhinav | last post: by
17 posts views Thread by MilkmanDan | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.