The Bitterest Pill I Ever Had To Swallow
The compelling alternative to JNI
JNI isn't for the faint of heart, and not just because the very premise of using it implies being capable in both Java and C or one of its various offshoots (I propose we use the pattern
*C* to match C, C++, C#, and Objective-C). The last time I spent serious quality time with JNI, I felt like I was writing 20 lines of plumbing for every one line of native code I wrote, to say nothing of wrangling Ant to build the whole thing. It didn't help that calling into Objective-C basically required two header files for each implementation: one from
javah with my JNI headers, the other to declare the Obj-C interface. Unsurprisingly, I didn't get very far before I lost interest and patience
Duncan McGregor took on a similar task -- providing Java wrappers around calls to Mac OS X's Cocoa framework -- but he had the sense to opt-out of JNI. Instead, he used the JNA library to dynamically make native calls, without needing to muck around with JNI. As JNA's proect page describes it:
The JNA library uses a small native library stub to dynamically invoke native code. The developer uses a Java interface to describe functions and structures in the target native library. This makes it quite easy to take advantage of native platform features without incurring the high overhead of configuring and building JNI code for multiple platforms.
The result of Duncan's work is Rococoa, "a generic Java binding to the Mac Objective-C object system. It allows the creation and use of Objective-C objects in Java, and the implementation of Objective-C interfaces in Java." The project initially started as a QTKit wrapper to expose QuickTime functionality, Rococoa examples of which are provided on a QuickTime page.
All without fighting with JNI over parameter lists, accessing Java values from C, or any of that rigamarole. Nice.
Also in Java Today,
the OpenJDK 6 project, the backport of OpenJDK's sources to the JDK 6 spec, has put out a b06 source release. As described in Joe Darcy's blog, imaging classes have been moved from closed to open, JAX-WS 2.1 has been included, and the SNMP portion of the build has been modified to not fail when binary plugs are absent. Several other improvements are included. Another build is expected within two weeks.
The latest edition, issue 160, of the JavaTools Community Newsletter has been published, with a look ahead to JavaOne and the java.net Community Corner mini-talks, tool news from around the web, new projects in the community, a new graduation (loc-counter, and a Tool Tip on writing Scala applications with Eclipse.
In today's Weblogs, Cay