Use Java as a "scripting" language in C ++

Let's say that Im is developing a cross-platform C ++ application that can be supplemented by users with add-ons. The application then offers the C ++ API and loads dynamic objects ( .so, .dlletc.). But for users it is necessary to compile for 6 target platforms (Windows x86/ x86-64, MacOS X x86/ x86-64and GNU / Linux x86/ x86-64).

To maintain portability, I thought of providing the Ruby API with libruby. With a little work, I came up with a proof of concept. The problem is that Im was worried about the performances . These add-ons can get big and CRUBY not so fast.

Then I thought, why not Java ?

  • Java bytecode has better performance, especially with JIT;
  • It is tolerated;
  • Distribution is simple, users must provide jar;
  • Users can provide closed-source add-ons (even if decompiling Java bytecode is not so difficult);
  • More people know about Java than Ruby.

The question is how to achieve this? I did some research and only found out about JNI (native Java interface). This, however, seems to be able to “invoke” C ++ from Java, and not vice versa.

+4
source share
1 answer

JNI Invocation API, C ++.

, , JNI C Java.

JNI ( Java). , , , "" ++ Java, .

, , Java C.

+3

All Articles