public class HelloWorld {
public native boolean isEmpty(int size);
//public native void test();
static {
System.loadLibrary("test");
}
public static void main(String[] args) {
System.out.println(new HelloWorld().isEmpty(0));
}
}
cmd运行以下命令生成.h,记得到java文件目录下
javac HelloWorld.java
javah -jni HelloWorld
如果有包的话,记得加包路径
我这里 vs2013 生成
[img]http://dl2.iteye.com/upload/attachment/0121/6375/4ab0ed16-af86-3b3f-bd9d-9baa53162de2.png[/img]
[img]http://dl2.iteye.com/upload/attachment/0121/6377/b460005f-b769-32a5-a052-720cd574998e.png[/img]
[img]http://dl2.iteye.com/upload/attachment/0121/6379/d4aa9ddb-03aa-368c-9aad-c0b514069020.png[/img]
[img]http://dl2.iteye.com/upload/attachment/0121/6383/a0e58fca-11e4-3b32-a8b6-a53a7e875877.png[/img]
[img]http://dl2.iteye.com/upload/attachment/0121/6385/94fea788-cd5d-3c1c-ae01-5d0e112f02d9.png[/img]
[img]http://dl2.iteye.com/upload/attachment/0121/6387/a05cdaac-f476-3731-8777-ff9585f9ac7b.png[/img]
添加刚刚生成的.h文件,
[img]http://dl2.iteye.com/upload/attachment/0121/6381/3cbc5c6b-c33c-3afa-833b-5aec794f17ab.png[/img]
创建.cpp
[img]http://dl2.iteye.com/upload/attachment/0121/6389/25db07bf-ffc2-3de4-a926-8fc00bb79242.png[/img]
在创建的cpp文件中写:
#include"test.h"
JNIEXPORT jboolean JNICALL Java_cn_osworks_aos_ethinkaos_service_kaipiao_impl_HelloWorld_isEmpty(JNIEnv *env, jobject obj, jint size){
if (size == 0){
printf("Hello World !\n");
return true;
}
return false;
}
生成DLL
[img]http://dl2.iteye.com/upload/attachment/0121/6391/e3cf694e-b072-3f3a-a5bc-4fb99a4c18c2.png[/img]
[img]http://dl2.iteye.com/upload/attachment/0121/6393/adb46ded-bc43-392e-b46b-f7418619328c.png[/img]
测试:
[img]http://dl2.iteye.com/upload/attachment/0121/6395/c5729fbe-2790-370e-9a4c-3d82a2b1fadf.png[/img]
参考:http://www.tuicool.com/articles/aMvUZb7,http://ironurbane.iteye.com/blog/375740,
http://blog.csdn.net/funneies/article/details/8949660
public native boolean isEmpty(int size);
//public native void test();
static {
System.loadLibrary("test");
}
public static void main(String[] args) {
System.out.println(new HelloWorld().isEmpty(0));
}
}
cmd运行以下命令生成.h,记得到java文件目录下
javac HelloWorld.java
javah -jni HelloWorld
如果有包的话,记得加包路径
我这里 vs2013 生成
[img]http://dl2.iteye.com/upload/attachment/0121/6375/4ab0ed16-af86-3b3f-bd9d-9baa53162de2.png[/img]
[img]http://dl2.iteye.com/upload/attachment/0121/6377/b460005f-b769-32a5-a052-720cd574998e.png[/img]
[img]http://dl2.iteye.com/upload/attachment/0121/6379/d4aa9ddb-03aa-368c-9aad-c0b514069020.png[/img]
[img]http://dl2.iteye.com/upload/attachment/0121/6383/a0e58fca-11e4-3b32-a8b6-a53a7e875877.png[/img]
[img]http://dl2.iteye.com/upload/attachment/0121/6385/94fea788-cd5d-3c1c-ae01-5d0e112f02d9.png[/img]
[img]http://dl2.iteye.com/upload/attachment/0121/6387/a05cdaac-f476-3731-8777-ff9585f9ac7b.png[/img]
添加刚刚生成的.h文件,
[img]http://dl2.iteye.com/upload/attachment/0121/6381/3cbc5c6b-c33c-3afa-833b-5aec794f17ab.png[/img]
创建.cpp
[img]http://dl2.iteye.com/upload/attachment/0121/6389/25db07bf-ffc2-3de4-a926-8fc00bb79242.png[/img]
在创建的cpp文件中写:
#include"test.h"
JNIEXPORT jboolean JNICALL Java_cn_osworks_aos_ethinkaos_service_kaipiao_impl_HelloWorld_isEmpty(JNIEnv *env, jobject obj, jint size){
if (size == 0){
printf("Hello World !\n");
return true;
}
return false;
}
生成DLL
[img]http://dl2.iteye.com/upload/attachment/0121/6391/e3cf694e-b072-3f3a-a5bc-4fb99a4c18c2.png[/img]
[img]http://dl2.iteye.com/upload/attachment/0121/6393/adb46ded-bc43-392e-b46b-f7418619328c.png[/img]
测试:
[img]http://dl2.iteye.com/upload/attachment/0121/6395/c5729fbe-2790-370e-9a4c-3d82a2b1fadf.png[/img]
参考:http://www.tuicool.com/articles/aMvUZb7,http://ironurbane.iteye.com/blog/375740,
http://blog.csdn.net/funneies/article/details/8949660