JNI in Mandriva Linux 2007

Hi, I tried the simple HelloWorld program in for JNI. I created the header file. And my list of files are

* HelloWorld.java

* HelloWorld.class

* Main.java

* Main.class

* HelloWorld.h

* HelloWorldImp.c

To create the header file i used the following command:

javah -jni HelloWorld

In my java i have a statement calledSystem.loadLibrary("hello"). Now i need to create the shared library hello. I have gcc. I tried the following command :

gcc -I /home/durai/jdk1.5/include/ HelloWorldImp.c -o hello.o

I got the hello.o file also. Now when i try to run the java using the following command

java -Dlibrary.java.path=/home/durai/New/testprograms/JNI/hello.o HelloWorld

it is giving the following exception:

Exception in thread"main" java.lang.UnsatisfiedLinkError: no hello in java.library.path

at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)

at java.lang.Runtime.loadLibrary0(Runtime.java:822)

at java.lang.System.loadLibrary(System.java:992)

at HelloWorld.<clinit>(HelloWorld.java:7)

What i have to do?. Please guide me.

[1212 byte] By [MAYAa] at [2007-11-27 11:16:38]
# 1

> Hi, I tried the simple HelloWorld program in for JNI.

> I created the header file. And my list of files are

>

> * HelloWorld.java

> * HelloWorld.class

> * Main.java

> * Main.class

> * HelloWorld.h

> * HelloWorldImp.c

>

> To create the header file i used the following

> command:

> javah -jni HelloWorld

>

> In my java i have a statement called

> System.loadLibrary("hello"). Now i need to

> create the shared library hello. I have gcc. I tried

> the following command :

> gcc -I /home/durai/jdk1.5/include/

> HelloWorldImp.c -o hello.o

>

> I got the hello.o file also. Now when i try to run

> the java using the following command

> java

> -Dlibrary.java.path=/home/durai/New/testprograms/JNI/h

> ello.o HelloWorld

> it is giving the following exception:

>

> Exception in thread "main"

> java.lang.UnsatisfiedLinkError: no hello in

> java.library.path

> at

> java.lang.ClassLoader.loadLibrary(ClassLoader.java:168

> 2)

> at

> java.lang.Runtime.loadLibrary0(Runtime.java:822)

> at

> java.lang.System.loadLibrary(System.java:992)

> at

> HelloWorld.<clinit>(HelloWorld.java:7)

>

> What i have to do?. Please guide me.

You haven't created a shared library. You have created an object file. To create a shared library, you use the -shared option with gcc:

gcc -shared -o libhello.so -I /home/durai/jdk1.5/include/HelloWorldImp.c

Jim S.

Niceguy1a at 2007-7-29 14:20:17 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

you have to change ur compiling command.. see what u have done is you have created object file.. whereas u have to create either Dynamic or shared library. hope it will solve ur prlm.

gohan_iitda at 2007-7-29 14:20:17 > top of Java-index,Java HotSpot Virtual Machine,Specifications...