Which of the following (or other) method would you recommend for accessing a C++ shared library from Java and why?
- JNI: I hear this has a number of pitfalls and is quite the undertaking?
- SWIG: Apparently this makes using JNI easier, but I've heard it has some problems too?
- JNA: I could write a C interface and then use JNA with it instead, which is apparently significantly easier than JNI?
- CNI: Apparently this is easier than JNI?
- Another library: it can't be commercial and I'd prefer something that is still well maintained (this would throw out JNIEasy, JNative, and JACE - I think).
I'm trying to go for minimal development time and problems down the road. Any info on pros/cons of each of these would be appreciated.
EDIT: Optimally, I'd be able to use my C++ objects in Java, but as I mentioned in #3, I could write a C interface using just functions if absolutely necessary. The C++ interface I'd like to have available in Java is something like:
class MyObj1
{
MyObj1(std::string, bool);
bool Func1();
void Func2(bool);
}
class MyObj2
{
MyObj2(MyObj1*);
ssize_t Func(uint8_t *, size_t, MyObj1);
}
The actual interface is a bit more complicated, but this demonstrates the type of objects and methods I'll be using. Some of the objects are derived, but the Java interface does not need to have any polymorphic behavior.