学习 JNI 示例代码
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
00.JNI
01.HelloStringFromC
02.Java2C
03.C2Java
.gitignore
README.md

README.md

Study-JNI

Platform: MacOS | Linux
Compile: gcc & javac & javah

How to use ?

generate jni header file

javah -jni <java file>

compile so library

gcc hello.c -fPIC -shared -o  libhello.so

jni test

public class HelloStringFromC {

    public static native String helloStringFromC();

    public static void main(String[] args) {
        System.out.println(helloStringFromC());
    }

    static {
        System.load("{your dir}/Study-JNI/01.HelloStringFromC/libhelloString.so");
    }
}