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!