12

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?

Martha Yi
  • 8,633
  • 3
  • 18
  • 8
  • Duplicate: http://stackoverflow.com/questions/438594/how-to-call-java-objects-and-functions-from-cpython, http://stackoverflow.com/questions/1201628/java-wrapper-to-perl-python-code – S.Lott Dec 07 '09 at 01:08

3 Answers3

15

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
  • 268,207
  • 37
  • 334
  • 440
8

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

Jason Orendorff
  • 42,793
  • 6
  • 62
  • 96
3

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
  • 26,309
  • 7
  • 59
  • 69