how to use jni in sarge
I have installed gcc and jdk1.4 at /usr/local
Which gcc command can generate shared library?
below is java anc C code:
//
class firstJNI
{
public native void displayHelloWorld();
public native void displayOther();
private native String getLine(String prompt);
static {
// System.loadLibrary("firstJNI");//This is firstJNI.DLL
// *if generated by borland
System.loadLibrary("firstjni");//This is firstjni.dll
// */
}
public static void main(String[] args)
{
firstJNI JN=new firstJNI();
JN.displayHelloWorld();
JN.displayOther();
String input = JN.getLine("Enter Some Thing ");
System.out.println("You Entered " + input);
}
}
/*firstJNI.c*/
#include <jni.h>
#include "firstJNI.h"
#include <stdio.h>
JNIEXPORT void JNICALL
Java_firstJNI_displayHelloWorld(JNIEnv *env, jobject obj)
{
printf("Hello world! This DLL was generated using Borland Compiler \n");
return;
}
JNIEXPORT void JNICALL
Java_firstJNI_displayOther(JNIEnv *env, jobject obj)
{
printf("Hello world! This is Other Function. This DLL was generated using Borland Compiler \n");
}
JNIEXPORT jstring JNICALL
Java_firstJNI_getLine(JNIEnv *env, jobject obj, jstring enter)
{
char buf[128];
const char *str = (*env)->GetStringUTFChars(env, enter, 0);
printf("%s", str);
(*env)->ReleaseStringUTFChars(env, enter, str);
scanf("%s", buf);
return (*env)->NewStringUTF(env, buf);
}
____________________________________________________________________________________
The fish are biting.
Get more visitors on your site using Yahoo! Search Marketing.
http://searchmarketing.yahoo.com/arp/sponsoredsearch_v2.php
Reply to: