Reputation: 1054
I was wondering, as in the title: Can I use JNI to bridge java code with languages other than c/c++/objective c, directly?
For example if I want to use Csharp from my java code, will I have to use JNI in the standard way by invoking a c/c++ method and from there somehow to call a csharp method?
Or is there a way that using JNI I can directly call Csharp code (meaning it would have some library similar to the one implementing the jni.h in c/c++)?
I am not looking for other solutions on how to bridge java/Csharp, just to know if its possible with JNI.
Upvotes: 1
Views: 566
Reputation: 1088
AFAIK, there´s no direct method. But there´s indirect ones, i.e. JNA instead of straight JNI.
The point is that JNI requires (at the very least) a method (normally, several methods) writen specifically to handle JNI parameter passing, and that requires C linkage (even if written e.g. in C++ or even csharp if you manage to do it).
JNA would be a way to provide this glue logic (and it sort of ressembles PINVOKE in .net), but it would be an indirect method. You would need to load e.g. a library written in csharp or manage to pass the csharp code to interpreter (somehow) and getting the results, and perhaps the csharp library you write would do exactly that, make a jni bridge that exposed some function that allows you to upload csharp scripts that would be executed via the .net interpreter and you would pass back the results via jni.
I remember using a JNI bridge that supported COM, and you could use COM to interact with (some) libraries wrote in whatever language, but then again, that would add another layer of indirection. Good luck!
Upvotes: 1