Can I use GCJ to create a library called from Python?

Is it possible to compile a library designed for Java with GCJ, get a DLL and call ctypes from python?

I'm interested in toxicology at the moment, but if anyone knows a toy example, that would be great!

+4
source share
1 answer

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.

+1
source

Source: https://habr.com/ru/post/1300347/


All Articles