Apologies for resurrecting the thread, but I think I have a better answer :-)
You could also use Py4J which has two parts: a library that runs in CPython (or any Python interpreter for that matter) and a library that runs on the Java VM you want to call.
There is an example on the frontpage and lots of documentation, but essentially, you just call Java methods from your python code as if they were python methods:
>>> from py4j.java_gateway import JavaGateway
>>> gateway = JavaGateway() # connect to the JVM
>>> java_object = gateway.jvm.mypackage.MyClass() # invoke constructor
>>> other_object = java_object.doThat()
>>> other_object.doThis(1,'abc')
>>> gateway.jvm.java.lang.System.out.println('Hello World!') # call a static method
The communication is done through sockets instead of JNI.
Disclaimer: I am the author of Py4J
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…