Purpose: Write C + + functions and let Java call
Java code
1. Create Hellojni.java file, write code as follows->cmd javac Hellojni.java get hellojni.class file
public class Hellojni {public native void display ();//native declaration function is its language implementation static {//Represents a static statement block System.loadlibrary ("Hellodll") ;//means load dynamic-link library hellodll library}public static void main (string[] args) {new Hellojni (). display ();}}
2. Javah Hellojni get HelloJNI.h file in cmd
The following is a C + + program
1. Create Hellodll to compile the dynamic library project
2. Select DLL Empty Project
3. Add HelloDll.h, HelloDll.cpp
4. Copy the contents of the HelloJNI.h to the HelloDll.h file
5. Copy the jni.h, Jawt_md.h, jni_md.h three header files from the JDK that installs Java to the Hellodll project.
Jni.h Location
Jawt_md.h, jni_md.h location
Copy to Hellodll project file
6. Need to configure the bottom file path item Right-click Property->vc++ project, including directory-> /hellodll;
7. Implementing Functions in HelloDll.cpp
8. Generate the HelloDll.dll library file
Run the program
1. Place the HelloDll.dll library file in the Hellojni.class file directory
2. In cmd, Java hellojni
Java-jni Java program to call C + + programs