Boost logo

Boost :

Subject: Re: [boost] Library proposal: Boost.JniTools - The easy way to call Java methods from C++ (build on top of JNI)
From: Matthew Chambers (matt.chambers42_at_[hidden])
Date: 2011-02-09 10:36:31


On 2/9/2011 4:22 AM, Boris Brodski wrote:
> Hello everyone,
>
>
> I'm the maintainer of the 7-Zip-JBinding project:
> - On SourceForge: http://sevenzipjbind.sourceforge.net/
> - On GitHub: https://github.com/borisbrodski/sevenzipjbinding/tree/RW (Check
> the RW branch)
>
> In order to call C++ code from Java and vice versa the JNI (Java Native
> Interface)
> should be used. This interface is low level and provides little safety. (Java VM
> crashes very easy)
> Also to get a good performance, a bunch of code is always needed to cache ids
> and some pointers
> returned from jni.
>
> In the new version of 7-Zip-JBinding (see git RW branch) I wrote a library, that
> solves some of JNI problems. It uses simple DSL (defines) to describe java
> classes/interfaces
> with their methods/fields. It generates from the DSL during pre-compile time
> some kind of
> easy to use skeletons around Java classes and interfaces, providing very simple
> access
> to their methods and fields.
>
> Here are the features:
> - Type-safe calls from C++ to Java - The compiler will check the number and type
> of
> all passed arguments to the called methods. The same applies to setting field.
> - Caching of method ids and class pointers.
> - Auto-determining java method signature from the DSL.
> - Consistent JNI low level error handling
> - Tools to debug checking and cleaning exceptions after each method call.
> - Code completion of the java methods and fields from C++ with IDE,
> capable of expanding defines (for example, with Eclipse CDT).
>
> In case, this library has a real chance to become a part of the Boost library,
> I would be happy to remove all the7-Zip-JBinding dependencies,
> implement missing features and discuss other possible improvements.
> It would be match better, if someone will volunteer to help me on this and
> share the responsibility.
>
>
> Regards,
> Boris Brodski

I'm certainly interested in such a library. Boost has utilities for making Python bindings, I don't
see why it shouldn't have them for Java bindings as well. I am maintaining a project which makes
considerable use of C++/CLI to bind its native libraries to .NET. I'm not as familiar with Java as
with C#; I was able to provide access to native fields with C# properties so that the interface is
pretty much exactly the same in C# as in C++. Is that possible in Java? We've had quite a few
requests for such bindings.

Thanks,
-Matt


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk