Search code examples
javac++cspringjava-native-interface

Call a C/C++ function in Java Spring Maven web application


I am a java developer and I have developed a web application for live video streaming in Java Spring and maven framework. I am trying to integrating the face recognition code with the existing web application. The face recognition code is in c language and I need to call those c functions in the java code. Can anybody guide me how to use this c code into a java web application? I have explored over the net regarding this but found nothing appropriate regarding this. I know JNI may works for this but how to integrate with web application?

I hope my requirement is clear;

(Spring+Hibernate+Maven) + (C-language code) -> web application

Thanks in advance.


Solution

  • You can create a class that loads a library from the System object like this:

    public class MyLibrary {
        static { System.loadLibrary("mylib"); }
        public static native boolean foo();
        public static native String bar();
    }
    

    You then have access to those methods like MyLibrary.foo()