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?

1

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

If using scipy and numpy, Jython may not be an option.
8

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

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.