JNAerator : bring native libs to Java
JNAerator (pronounce ‘generator’) simply parses C & Objective-C headers and generates the corresponding JNA and Rococoa Java interfaces (it also has a very limited support for C++).
This lets Java programmers access native libraries transparently, with full IDE support and little to no hand-tweaking.
Users who are looking for ready-to-use libraries should check the NativeLibs4Java project.
Just. Forget. JNI.
It can be used in command line or through its handy but limited GUI :
![]() | JNAeratorStudio (direct Web Start Link) |
Features
(see Roadmap for planned features)
- Handles most of ANSI-C (not everything yet, though), including (but not restricted to) :
- structs & unions (including bit fields)
- functions and callbacks (including varargs)
- typedefs, macro definitions, constants & enums, global variables...
- generates C++ name mangling for functions & static methods : no need to declare functions in extern "C" {...} blocks (note, however, that most C++ constructs will be skipped gracefully). Only supports GCC4 and MSVC9's mangling schemes (Intel C++ Compiler is on the works).
- embeds a full-fledged C preprocessor (the great thirdparty Anarres JCPP library, under the Apache 2.0 license)
- parses Visual Studio solutions (*.sln) and projects (*.vcproj) files to retrieve source files, preprocessor symbols and include paths
- knows about standard compilers and SDKs setups (defaults to know where to find core headers in Visual Studio, frameworks under Mac OS X… GCC not handled automatically yet but paths can be added to command line)
- converts parsed comments to JavaDocs
- provides multiple choices of function signatures where possible.
- supports JNA's two wrapping modes : interface mapping mode and new experimental direct calling mode (-direct switch)
- generates complete Objective-C mappings for use with Rococoa :
- may analyze many frameworks at the same time
- handles all methods added to a class by parsed protocols
- parses BridgeSupport files, either as a primary source of information or as a complement. BridgeSupport files can be provided in command line or will be fetched automatically when specifying a -framework SomeFramework argument.
- Supports DLL symbols extraction (-scanSymbols switch), demangling and parsing on Windows (very experimental, will only yield interesting and usable results for C++ functions - not methods, as neither fastcall nor thiscall are supported so far).
For instance, the function :void CopyBytes(char* dest, const char* source, size_t n, const int* intArray);Would get the following three Java definitions :// raw pointer types @Deprecated void CopyBytes(com.sun.jna.ptr.ByteByReference dest, com.sun.jna.ptr.ByteByReference source, com.sun.jna.NativeLong n, com.sun.jna.ptr.IntByReference intArray); // prefer nio buffers void CopyBytes(java.nio.ByteBuffer dest, java.lang.String source, com.sun.jna.NativeLong n, java.nio.IntBuffer intArray); // prefer primitive arrays where possible, otherwise nio buffers when possible void CopyBytes(java.nio.ByteBuffer dest, java.lang.String source, com.sun.jna.NativeLong n, int intArray[]);However, some functions have only one possible translation : int f(float); becomes : int f(float arg1);
Quick Start
Take a look at the Documentation...
Then launch JNAeratorStudio (direct Web Start Link) and start converting your C/Objective-C headers straight away !
News, Announcements, Discussions
News and announcements are made on the author's blog.
Discussions and support take place on JNA's users mailing list.
Bug reports and requests for enhancements should be filed in the Issues section.
Credits and License
JNAerator is written and maintained by Olivier Chafik and is distributed under the terms of the LGPL license, but it relies on many great thirdparty libraries.
Please read the CreditsAndLicense page for detailed Copyright notices and licenses.

