I’m currently using the JNI to generate C headers for native methods being used in a Java class ABC. However, I’d like to use these methods elsewhere, in another class XYZ, so hence I made a class called cLib which basically just had the prototypes of the native methods, and which when generated gave me the header file for the methods I needed.
The problem is, JNI attaches the name of the Java class the prototype was declared in to the name of the function in the header file, so would I need to just separately generate two header files for each of the Java classes ABC, XYZ?
Best.
Three options:
public class Boo { public V doSomething(...) { return (Common.doSomething(...)); } } public class Wow { public V doSomething(...) { return (Common.doSomething(...)); } } public class Common { public static native V doSomething(...); } /** Trivial JNI Implementation omitted... */public class Boo { public V native doSomething(...); } public class Wow { public V native doSomething(...); } /** Both JNI methods call same C/Assembly native function, similarly... */see
java.lang.CompilerCheers,
leoJava