---jni simple implementation of Java Learning Article (cont.)

Source: Internet
Author: User

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.)

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.