javajava-native-interface

JNI: Generated file name and functions are cumbersome


I decided to put my Java "native"-methods class in some package within my program.

When I call javac -h on that java class, it generates a file named com_example_foo_baz_MyJniInterface.h

The same applies to that auto-generated functions inside the header file.

I know it's a default behaviour that probably supposed to ensure uniqueness, but is there a way to generate the file without this cumbersome prefix?

Thanks!

EDIT:
if the file is not going to change too often (or at all) is there a point to stick with the auto-generation option? Instead, I can edit the file once and that's it.


Solution

  • As specified in documentation and as you correctly supposed, the native methods name in the header file is build to obtain unicity, and to let the vm link correctly the java and the C counterpart at runtime.

    Anyway, the name of the generated header file has nothing to do with uniqueness of methods, and may be changed after the creation; in the javac command documentation there is no option to force the output file, at most you can tell the command the directory where to place the .h file.

    For the contents of the headers file, since it is autogenerated, I suggest not to edit them; consider that the .c file that will implement the methods in .h would be a proxy to some real implementations that may be implemented in C or C++ (and those would have less fancy names).