JAVA JNI ʹÓÃʵÀý
JAVA¿ÉÒÔͨ¹ýJNI½Ó¿Ú·ÃÎʱ¾µØµÄ¶¯Ì¬Á¬½Ó¿â£¬´Ó¶øÀ©Õ¹JAVAµÄ¹¦ÄÜ¡£Ê¹ÓÃJAVA JNI½Ó¿ÚÖ÷Òª°üÀ¨ÒÔϲ½Ö裺
(1)±àдJAVA´úÂ룬עÃ÷Òª·ÃÎʵı¾µØ¶¯Ì¬Á¬½Ó¿âºÍ±¾µØ·½·¨£»
(2)±àÒëJAVA´úÂëµÃµ½.classÎļþ£»
(3)ʹÓÃjavah -jni Éú³É¸ÃÀà¶ÔÓ¦µÄCÓïÑÔ.hÎļþ£»
(4)ʹÓÃC/C++ʵÏÖ£¨3£©Éú³ÉµÄ.hÎļþÖÐÉùÃ÷µÄ¸÷º¯Êý£»
(5)±àÒëC/C++ʵÏÖ´úÂëÉú³É¶¯Ì¬Á¬½Ó¿â¡£
±¾ÎÄʹÓÃÒ»¸ö¼òµ¥µÄhelloWorldʾÀýÑÝʾJNIµÄʹÓá£
£¨1£©±àдJAVA´úÂë
public class helloWorld
{
public native void SayHello(String name);
static
{
System.loadLibrary("examdll");
}
public static void main(String [] argv)
{
helloWorld hello = new helloWorld();
hello.SayHello("myName");
}
}
£¨2£©±àÒëJAVA´úÂë
javac helloWorld.java
£¨3£©Éú³ÉʵÏÖº¯ÊýÍ·Îļþ
javah -classpath . helloWorld
µÃµ½µÄÎļþÄÚÈÝÈçÏ£º
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class helloWorld */
#ifndef _Included_helloWorld
#define _Included_helloWorld
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: helloWorld
* Method: SayHello
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_helloWorld_SayHello
(JNIEnv *, jobject, jstring);
#ifdef __cplusplus
}
#endif
#endif
£¨4£©ÔÚVCÖÐʵÏÖÉÏÊöº¯Êý
#include "helloWorld.h"
#include <stdio.h>
#include <string.h>
void JNICALL Java_helloWorld_SayHello(JNIEnv * env, jobject obj, jstring str)
{
jboolean b = true;
char s[80];
memset(s, 0, sizeof(s));
strcpy_s(s ,(char*)env->GetStringUTFChars(str, &b));
printf("Hello, %s", s);
env->ReleaseStringUTFChars(str , NULL);
}
**** ÕâÊ
Ïà¹ØÎĵµ£º
ÏÈ¿´¸öÀý×Ó£º
½Ó¿Ú
package example;
public interface Basic {
public void hello();
}
½Ó¿ÚµÄʵÏÖÀà
package example;
public class BasicService implements Basic {
public void hello() {
Sysyt ......
write by ¾ÅÌìÑãôá(JTianLing) -- blog.csdn.net/vagrxie ÌÖÂÛÐÂÎÅ×é¼°Îļþ Technorati ±êÇ©: JAVA,JAVA Applet,Applet Tag,Deploy Applet,´ÓC++µ½JAVA ǰÑÔ Ôø¾£¬ÎÒÓÐÒ»¸öÃÎÏ룬ÄǾÍÊÇÎҵijÌÐòÄÜÈÃÈ˲»ÐèÒªÏÂÔØ¾ÍÄÜͨ¹ýä¯ÀÀÆ÷ÔËÐУ¬¿ÉϧѧϰµÄC,C++µÈ¶¼²»¾ß±¸´ËÄÜÁ¦£¬Ñ§Ï°ÍêPythonºó£¬·¢ÏÖÆäÒ²½ö½öÊÇÒÔ·þÎñÆ÷ ......
public class Fibonacci {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
NumOfFibonacci(9);
}
public static int MyFibonacci(int i){
if(i>0) {
if(i == 1)return 1;
if(i == 2)return 1;
else return MyFibonacc ......
/**
* this¹Ø¼ü×ÖÓ÷¨
*/
public class Flower {
int petalCount = 0;
String s = "initial value";
Flower(int petals){
petalCount = petals;
System.out.println("Constructor with one int arg");
}
Flower(String ss){
System.out.println("Constr ......