You will need to use the Java Native Interface (JNI) , which is a set of C / C ++ functions that allow you to use your own code for an interface with java code (i.e. get parameters from calls to Java functions, return results, etc. d.). Write a shell C library that accepts JNI calls and then calls your external library.
For example, the following function calls the updateHandlers method on its own object (which has been stored for so long on the Java side).
class MyImpl { void updateHandlers(JNIEnv *env) { this->contentHandler = ....; } } JNIEXPORT void JNICALL Java_package_Classname_updateHandlers0 (JNIEnv *env, jobject obj, jlong ptr) { ((MyImpl*)ptr)->updateHandlers(env); }
Relevant declarations in package.ClassName:
private long ptr; //assigned from JNI public void updateHandlers() { if (ptr==0) throw new NullPointerException(); updateHandlers0(ptr); } private native void updateHandlers0(long ptr); static { try { /*try preloading the library external.dll*/ System.loadLibrary("external"); } catch (UnsatisfiedLinkError e) { /*library will be resolved when loading myjni*/ } System.loadLibrary("myjni"); //load myjni.dll }
source share