Eclipse JNI Environment Setup and use

Source: Internet
Author: User

Build the Environment
    1. Installing the Java SDK and adding environment variables
    2. Installing Elipse Java and CDT plugins
    3. Install TDM64-GCC and add environment variables Baidu Cloud (password: MJDI)
    4. Install Msys and add environment variables Baidu Cloud (password: j2i6)
JNI use steps to create a Java engineering Jni_demo

Create the class Jnidemo and write the following:

package jni_demo;public class JNIDemo {    public native void sayHello();        public static void main(String[] args) {        // 调用动态链接库        System.loadLibrary("libJNIDemo");        JNIDemo jniDemo = new JNIDemo();        jniDemo.sayHello();    }}

Open the command line, enter the SRC path of the Java project, and enter the following command to generate the local method header file:

Create a dynamic library Jnidemo

Project header file configuration:

Create the SRC directory, move the generated header files to the SRC directory, and create the corresponding. c files, and write the following:

#include "jni_demo_JNIDemo.h"JNIEXPORT void JNICALL Java_jni_1demo_JNIDemo_sayHello  (JNIEnv *env, jobject obj){    printf("Hello Java, I am C.");}

Project right: Build project, generate dynamic library LibJNIDemo.dll

Java Call DLL

Create the Sibling directory lib in the SRC directory of the Jni_demo project, move the LibJNIDemo.dll to the directory, and configure the Dynamic library path:

The final project structure is as follows:

Run the Java project and output the following results to prove that the call was successful:

Sample Code Address

Baidu Cloud (password: qyq4)

Reference links

Eclipse calls the setup of the JNI environment
Teach you how to invoke JNI full strategy through Eclipse engineering configuration

In this paper, according to the above two articles combined with their own development environment, the implementation of the JNI call, and provide sample code, for reference only.

Eclipse JNI Environment Setup and use

Related Article

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.