Compile HelloWorld.java
javac HelloWorld.java
Generate HelloWorld.h
javah HelloWorld
#include <jni.h>
#include "HelloWorld.h"
#include <stdio.h>
JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
printf("Hello world!\n");
return;
}
编译的时候,include , " Java_home/include ; Java_home/include/win32"
编译选项:env.MergeFlags('-Wl,--kill-a') 。
把 .dll 拷贝到 .class 目录,
java HelloWorld
JNI_CreateJavaVM
int JniInit::createJvm(JavaVM **jvm, JNIEnv **env,
char *classpath,char * jvmOptions){
JavaVMInitArgs vm_args;
JavaVMOption options[2];
options[0].optionString = classpath;
options[1].optionString = jvmOptions;
vm_args.version = JNI_VERSION_1_2;
vm_args.options = options;
vm_args.nOptions = 2;
//vm_args.ignoreUnrecognized = JNI_TRUE;
int ret=JNI_CreateJavaVM(jvm, (void**)env, &vm_args);
return ret;
}
把 :C:\Program Files\Java\jdk1.6.0_11\jre\bin\ :(client) 加到path.
include:C:\Program Files\Java\jdk1.6.0_11\include\
link: C:\Program Files\Java\jdk1.6.0_11\lib\jvm.lib
javac HelloWorld.java
Generate HelloWorld.h
javah HelloWorld
#include <jni.h>
#include "HelloWorld.h"
#include <stdio.h>
JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
printf("Hello world!\n");
return;
}
编译的时候,include , " Java_home/include ; Java_home/include/win32"
编译选项:env.MergeFlags('-Wl,--kill-a') 。
把 .dll 拷贝到 .class 目录,
java HelloWorld
JNI_CreateJavaVM
int JniInit::createJvm(JavaVM **jvm, JNIEnv **env,
char *classpath,char * jvmOptions){
JavaVMInitArgs vm_args;
JavaVMOption options[2];
options[0].optionString = classpath;
options[1].optionString = jvmOptions;
vm_args.version = JNI_VERSION_1_2;
vm_args.options = options;
vm_args.nOptions = 2;
//vm_args.ignoreUnrecognized = JNI_TRUE;
int ret=JNI_CreateJavaVM(jvm, (void**)env, &vm_args);
return ret;
}
把 :C:\Program Files\Java\jdk1.6.0_11\jre\bin\ :(client) 加到path.
include:C:\Program Files\Java\jdk1.6.0_11\include\
link: C:\Program Files\Java\jdk1.6.0_11\lib\jvm.lib