Executing Java code for calling Native Method of C On Unix

 
Post new topic   Reply to topic    34SP.com Forum Index // Other OS Help
View previous topic :: View next topic  
Author Message
sbeyonduf007
34SP Newbie
34SP Newbie


Joined: 08 Nov 2006
Posts: 1

PostPosted: Wed Nov 08, 2006 1:06 pm    Post subject: Executing Java code for calling Native Method of C On Unix Reply with quote
Executing Java code for calling Native Method of C On Unix Machine
hi all
i have a unix machine (FBD). I have Also installed java of Version (j2sdk1.4.1_07) on unix machine. Now i

want to Call C Native function in Java Which is declared as Native. i am doing this by following steps:
1) Making Echo.java File Which is having The following lines of code.
class Echo {
public native void runEcho();

static {
System.loadLibrary("echo");
}

public static void main(String[] args) {
new Echo().runEcho();
}
}
2) Compiling the Code:
$ javac Echo,java
$ javah Echo ----- which will make the header file used in c programe
3) writing the EchoImp.c File Which contains the following line of code
#include "jni.h"
#include "Echo.h"//the java class above compiled with javah
#include <stdio.h>

JNIEXPORT void JNICALL
Java_Echo_runEcho(JNIEnv *env, jobject obj)
{
char buf[64];
gets(buf);
printf(buf);
}
4) Making the Library echo
$ cc -G -I/usr/local/java/include -I/usr/local/java/include/linux
Echo.c -o libecho.so
5) Now Setting The Libarary Path
$ setenv LD_LIBRARY_PATH <Path>
6) Now Finally Excute the Java Program to call c function
$ java Echo


but while executing i m getting Error Like :
Exception in thread "main" java.lang.UnsatisfiedLinkError: no echo in java.libra
ry.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1403)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:832)
at Echo.<clinit>(Echo.java:5)

i have also set the path but no results ....


Kamal Kant
sb
Back to top
View user's profile Send private message
Post new topic   Reply to topic    34SP.com Forum Index // Other OS Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Powered by phpBB © 2001, 2002 phpBB Group