How to Use JNI: How to Use JNI

Source: Internet
Author: User

How to Use JNI: How to Use JNI

1. in java, public native void + method name ("");
2. Then load the required underlying so file system. loadLibrary ("so file name cannot be suffixed ")
3. When you need to call the native method, you can call it as a normal method.
The following is the implementation of the underlying C or C ++
1. Find the directory where your project is located and open cmd to enter the directory where your project is located
2. javac-d. Add the class name of your native class. java
2. Generate the header file using the javah + class name
3. paste the header file, that is, the. h file, to the directory where your C implementation code is located.
4. Then introduce the header file # include "file name. h" on your C file"
5. Then introduce the jni. h file C: \ Program Files (x86) \ Java \ jdk1.6.0 _ 10 \ include.
And C: \ Program Files (x86) \ Java \ jdk1.6.0 _ 10 \ include \ win32 jni_md.h Files
Open jni. h. If you find that jni_md.h has been introduced, you do not need to introduce it on C.
6. Then, import the system output # include <stdio. h>. Note that angle brackets represent the system directory, and double quotation marks represent the current directory.
7. Copy the C code method to be implemented in. h to C, change the semicolon to braces, and write the logic to be implemented in it.
8. Then, compile ctrl + shift + d.
9. Then, go to the directory compiled by C code to find the. c file you have produced, and copy it to \ Program Files (x86) \ Java \ jdk1.6.0 _ 10 \ bin.
10 note that the so file name referenced in java must be the same as the so file name generated by you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.