Looking for a convenient way to call Java from C++

前端 未结 9 957
醉话见心
醉话见心 2021-01-30 13:55

It seems most documentation or helper libraries relating to JNI (Java Native Interface) are concerned with calling native code from Java. This seems to be the main use of it, ev

9条回答
  •  青春惊慌失措
    2021-01-30 14:27

    I'm one of the prinicpal architects for Codemesh's language integration products, including JunC++ion. We have been doing this kind of integration since 1999 and it works really well. The biggest problem is not the JNI part. JNI is tedious and hard to debug, but once you get it right, it mostly just keeps working. Every now and then, you get broken by a JVM or an OS update, and then you have to fine-tune your product, but in general it's stable.

    The biggest problem is the type system mapping and the trade-offs between general usability and targeted solution. You state for example that you don't like the fact that JACE treats all object references as globals. We do the same thing (with some escape hatches) because it turns out that this is the behavior that works best for 95% of customers, even if it hurts performance. If you're going to publish an API or a product, you have to pick the defaults that make things work for most people. Picking local references as the default option would be wrong because more and more people are writing multithreaded applications, and a lot of Java APIs that people want to use from other languages are intrinsically multithreaded with asynchronous callbacks and the like.

    We also found out that you really want to give people a GUI-based code generator to create the integration specification. Once they've specified it, you use the CLI version to integrate it into the nightly build.

    Good luck with your project. It's a lot of work to get right. We spent several years on it and we're still making it better regularly.

提交回复
热议问题