In the previous article, in the generation of the header file when there was a problem, fortunately Kung Fu, the ultimate difficulty was overcome!
Next I'm going to write step two of the 9th) step:
Step Two:
9) Set up the 64-bit compilation platform:
Open the Microsoft Visual stutio--->file--->new--->project ...--->
OK--->next--->
After finish, an empty project is generated:
The default is to use the Win32 platform, and my operating system is 64-bit, so:
Click Configuration Manager ...
The default is as follows:
New platform:
So far, the 64-bit compilation platform has been set up.
10) Implement the SayHello () method in C + + and compile the source file into a sayhello.dll dynamic-link library:
Copy the Dickens generated header file from the previous article to the SayHello project:
Select the header Files under the SayHello item---> Right-click Add--->existing item ...---> select com_ryze_jni_test_helloworld.h---> So the header file is added to the project:
Click can see the header file declared a long name called Java_com_ryze_jni_test_helloworld_sayhello function, the name of the function is Java_ Package Name _ Class Name _ Method name
The next step is to select the source Files under the project---> Right-click Add--->new item ...--->
Create a new C + + empty file with the name source
Write the code in the empty file as follows:
#include <iostream> #include "com_ryze_jni_test_helloworld.h" using namespace std; Jniexport void Jnicall Java_com_ryze_jni_test_helloworld_sayhello (jnienv *, jobject) {cout<< "Hello world!" <<endl;}
The header file is then opened and the header file
Rewritten as:
Then add the JDK's include directory
C:\Program Files\java\jdk1.7.0_45\include
Jni.h and directories under the
C:\Program Files\java\jdk1.7.0_45\include\win32
Under the Jni_md.h copy to the project source file directory
Then compile:
Compile successfully, at this time generate the Sayhello.dll file we need in the Debug directory:
11) Add the generated Sayhello.dll dynamic link library to the PATH environment variable:
12) Call the SayHello () method in the dynamic-link library in Java:
---jni simple implementation of Java Learning Article (cont.)