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);
}
**** ÕâÊ
Ïà¹ØÎĵµ£º
1¡¢¼òµ¥ java
2¡¢¿ÉÒÆÖ²ÐÔ Ò»´Î±àÒë´¦´¦ÔËÐÐ
3¡¢ÃæÏò¶ÔÏó
4¡¢·Ö²¼Ê½ java°Ñ´ò¿ªÌ×½Ó×ֵȷ±ËöµÄÍøÂçÈÎÎñ±äµÄ·Ç³£¼òµ¥
5¡¢½¡×³ÐÔ java±àÒëÆ÷¿ÉÒÔ¼ì²é³öÆäËûÓïÑÔÔÚÔËÐÐʱ²ÅÄÜ·¢ÏֵĴíÎó
6¡¢¶àÏß³Ì ¶àÏ̵߳ļòµ¥ÐÔÊÇjavaÁ÷ÐÐÓÚ·þÎñÆ÷±à³ÌµÄÖ»ÒªÔÒò
7¡¢°²È«
8¡¢½á¹¹ÖÐÁ¢
9¡¢¶¯Ì¬
¡£¡£¡£ ......
1. ÒýÑÔ
¡¡¡¡½üÄêÀ´£¬Ëæ×ÅInternet/Intranet½¨Íø¼¼ÊõµÄ·ÉËÙ·¢Õ¹ºÍÔÚÊÀ½ç·¶Î§ÄÚµÄѸËÙÆÕ¼°£¬¼ÆËã»ú
¡¡¡¡Ó¦ÓóÌÐòÒÑ´Ó´«Í³µÄ×ÀÃæÓ¦ÓÃתµ½WebÓ¦Ó᣻ùÓÚB/S£¨Browser/Server£©¼Ü¹¹µÄ3²ã¿ª·¢Ä£Ê½Öð½¥È¡´úC/S£¨Client/Server£©¼Ü¹¹µÄ¿ª·¢Ä£Ê½£¬³ÉΪ¿ª·¢ÆóÒµ¼¶Ó¦Óú͵ç×ÓÉÌÎñÆÕ±é²ÉÓõļ¼Êõ¡£ÔÚWebÓ¦Óÿª·¢µÄÔçÆÚ£¬Ö÷ҪʹÓõ ......
Ô´´úÂ룺
import com.sap.mw.jco.*;
public class control extends Object
{
public static void main (String str[])
{
control control=new control();
}
int count;
JCO.Client mConnection;
JCO.Repository mRepository;
String[] SAPInterfaces;
public control()
{
try {
& ......
1.Ê×ÏÈ´´½¨Ò»¸ö¹¤³ÌËæ±ãÃüÃû¡£
2.´´½¨Ò»¸öÀàÃüÃûΪReg.
3.Ö´ÐдúÂë
4.ÊäÈë×¢²áµÄÐÕÃû£¬ÏÔʾÀ¸Ä¿»á³öÏÖplease input register name:£¬Ö»ÒªÊäÈëÓ¢ÎÄÃûÈ»ºó»Ø³µ£¬×¢²áÂë¾Í³öÀ´ÁË¡£°ÑÐÕÃûºÍ×¢²áÂëÏñ£º
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public clas ......