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

前端 未结 9 873
醉话见心
醉话见心 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:24

    I also had many difficulties getting JNI to work on different operating systems, coping with 32/64-bit architectures and making sure the correct shared libraries were found and loaded. I found CORBA (MICO and JacORB) difficult to use too.

    I found no effective way to call from C/C++ into Java and my preferred solutions in this situation are to run my Java code as either:

    1. a stand-alone program that I can easily run from C/C++ programs with java -cp myjar.jar org.foo.MyClass. I guess this is too simplistic for your situation.

    2. As a mini-server, accepting requests from C/C++ programs on a TCP/IP socket and returning results through this socket too. This requires writing networking and serializing functions but decouples the C/C++ and Java processes and you can clearly identify any problems as being in the C++ side or Java side.

    3. As a Servlet in Tomcat and make HTTP requests from my C/C++ program (other servlet containers would also work too). This also requires writing networking and serializing functions. This is more like SOA.

提交回复
热议问题