Using JNI to execute a java jar from a C++ program, using g++ or eclipse

后端 未结 2 1907
孤街浪徒
孤街浪徒 2020-12-10 20:58

I\'m trying to call / execute a java jar from a C++ program.

Here are the options I\'ve found so far:



        
相关标签:
2条回答
  • 2020-12-10 21:46

    I had a similar issue and realized the problem was that I was compiling, in Ubuntu, with a version of JDK that was meant for Windows and not Linux. It worked when I compiled in Cygwin instead. Alternatively, if I wanted to keep using Ubunutu, I could have tried a JDK for Linux instead.

    0 讨论(0)
  • 2020-12-10 21:54

    Usually you have to add some kind of platform specific directory as well like on Linux:

    g++ -I /usr/lib/jvm/jdk1.6.0_34-x86/include/ -I /usr/lib/jvm/jdk1.6.0_34-x86/include/linux Hello.cpp
    

    because a few macros (like JNICALL) are set up there. Hopefully that'll fix the jni.h error cascade.

    EDIT: Still stuck? Try:

    JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
    

    It'll at least get past the compilation problem. I don't know if it'll work, since I've not tried this before.

    0 讨论(0)
提交回复
热议问题