C/C++ header to java

Is there any good tool to generate java (+JNI support if needed) from a header file so that a C or C++ library can be used as-is. Kind of a reverse of javah. The real functionality would be in the C/C++, the Java would be only a shim on top for certain users.

I'm no expert on JNI but as far as I can see Javah forces you to do this back to front. It forces you to have JNI-isms penetrating unecessarily into the C code unless you write a conversion layer yourself. And writing a conversion layer by hand is basically a waste of time, since all the information is there in the header file to begin with.


For C, you can use JNA. You do have to declare function signatures redundantly in Java, but do not have to write any glue code. JNA is very easy to use.

For C or C++, you can use SWIG. SWIG is a little more complex to use, but automatically generates Java wrappers for C++ classes. I'm enjoying it.

JNAerator does exactly that : it reads C/C++/ObjectiveC headers and outputs Java bindings that rely on BridJ (C/C++), JNA (C only) or Rococoa (ObjectiveC, uses JNA).

Looks like SWIG works with Java: http://www.swig.org/Doc2.0/Java.html

Maybe this isn't exactly what you're looking for, though, since you do have to add SWIG directives…

Need Your Help

How do I stop name-mangling of my DLL's exported function?

c++ c extern name-mangling

I'm trying to create a DLL that exports a function called "GetName". I'd like other code to be able to call this function without having to know the mangled function name.

Why does Log4Net run so slow in my Windows Service?

.net-2.0 service log4net c#-2.0 performance

I have a windows service that uses log4net. We noticed that the service in question was running painfully slow so we attached a debugger to it and stepped through. It appears that each time it trie...