If you want to intercept Java-Python, you would be much better off using Jython and then invoking it across the border this way.
However, yes, you can call an external library from Java; but you donβt need GCJ for this. Most likely, you can just call the JVM instance inside your Python runtime, and then call your method (s) to do this.
JNI Call Specification
Basically, you want to create your virtual machine at startup, and then call your method (s) whenever you want:
// Do this once per session, eg an __init__ JNI_CreateJavaVM(&jvm, &env, &vm_args); // When needed invoke Example.foo(int) jclass cls = env->FindClass("Example"); jmethodID mid = env->GetStaticMethodID(cls, "foo", "(I)V"); env->CallStaticVoidMethod(cls, mid,100);
You can write simple C-wrapper code to call this from ctypes for you. However, JavaVM is a structure structure with multiple void * pointers, so it can be nontrivial to do this directly.
source share