First JNI exploration, small experiment, and first jni Exploration

Source: Internet
Author: User

First JNI exploration, small experiment, and first jni Exploration

First jni test :(

Documentation: http://download.csdn.net/detail/u010476739/8065987)

Test environment, vs2010 flagship edition, win7 flagship 64-bit MyEclipse2014

1. Compile a java class:

Public classNativeClass {

Public native voidShow ();

Public static voidMain (String [] args ){

System.LoadLibrary("NativeClass ");

NewNativeClass (). show ();

}

}

 

2. Compile the file into a class file, place the class file on the desktop, and use javahNativeClass to generate the NativeClass. h file ,:


 

 

3. Open vs2010 to create the win32 type of the project:







After the creation is successful, write the code:

// NativeClass. cpp: Define the definition? DLL application | use? What is the degree of degree in the descending order of Cheng Yu? Export? Outbound? Letter ¥ number ° y. Zookeeper

//

 

# Include "stdafx. h"

# Include "jni. h"

# Include "NativeClass. h"

 

 

JNIEXPORT void JNICALL Java_NativeClass_show

(JNIEnv *, jobject)

{

Printf ("Helloworld! \ N ");

Return;

}

 

Final



Because the entered Code contains: # include "jni. h "# include" NativeClass. h ", so we need to put these two header files in the vs2010 directory, jni. h: E: \ Java \ jdk1.7.0 _ 45 \ include \ path (or you need to copy jawt_md.h In the subdirectory win32 under this directory together ),

 


Then configure the configuration when vs2010 is generated: (because my system is win7 64-bit, the compiled dll is 64bit, and eclipse also needs to call 64-bit), the configuration steps are as follows:




 




Then select Run or f5,


Find the dll file after generation,



Put this dll file into eclipse,



Let's run it in eclipse. The effect is as follows:



OK, success!

 




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.