[] JNI Java Basics Getting Started

1, issue: javah or javac -h

After configuring the environment variables of good java, java and javac it can all be used, but problems arise with javah.

Will be reported error

Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home/bin/javah" (-1)

Later in the online search, I found jdk-10.0.2, this version of jdk canceled javah, instead of direct use javac -h

Then we can directly use the javac -h

 

2, in addition to the above problems, the remaining process may refer to: https://my.oschina.net/gschen/blog/1613890

Summarizes the process:

(1) preparation of java file, define native method, loading step 4 jni generated dynamic link library;

. (2) javac java files compiled class files, javac HelloNative.java -h c compile header files, header files which declares native methods;

(3) The file header, the new file c, c achieved by a method of native language;

(4) Use gcc to compile c files into a dynamic link library, jni file:

gcc HelloNative.c -o libHelloNative.jnilib -dynamiclib -I/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/include/ -I/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/include/darwin/

(5) run java program: java HelloNative

Guess you like

Origin www.cnblogs.com/jiangyi-uestc/p/11222135.html