tags:

views:

183

answers:

3

I have a Java class library (3rd party, proprietary) and I want my python script to call its functions. I already have java code that uses this library. What is the best way to achieve this?

+14  A: 

Can you run your current Python scripts under Jython ? If so, that's probably the best way, since the Java library can be exposed directly into Jython as scriptable objects.

Failing that, there are a number of solutions listed here.

Brian Agnew
+1. It's hard to beat Jython as the solution here.
John Feminella
If using scipy and numpy, Jython may not be an option.
Sney
+7  A: 

The other answer is JPype, which allows CPython to talk to Java. It's useful if you can't switch to Jython.

Jason Orendorff
+3  A: 

There's also JCC which is not mentioned on the Caltech page.

Quote:

JCC is a C++ code generator that produces a C++ object interface wrapping a Java library via Java's Native Interface (JNI). JCC also generates C++ wrappers that conform to Python's C type system making the instances of Java classes directly available to a Python interpreter.

When generating Python wrappers, JCC produces a complete Python extension via the distutils or setuptools packages.

akaihola