There is no real difference between JNI on Linux and JNI on other
operating
systems (and not suppose to be). Look at Sun Java tutorial on JNI:
http://java.sun.com/docs/books/tutorial/native1.1/index.html

Take the source code for HelloWorld example and follow the instructions:
after the first step the directory listing will be:
step 1: Writing HelloWorld.java file

my_directory>ls -l
HelloWorld.java

step 2: Java compilation
javac HelloWorld.java

my_directory>ls -l
HelloWorld.java
HelloWorld.class

step 3: Generating HelloWorld.h file  (Don't use .java extension)
javah -jni HelloWorld

my_directory>ls -l
HelloWorld.java
HelloWorld.class
HelloWorld.h

step 4: Writing HelloWorldImp.c file
my_directory>ls -l
HelloWorld.java
HelloWorld.class
HelloWorld.h
HelloWorldImp.c

step 5a: Compilation of C file
gcc -I//homes/nikom/work/Java/jdk1.2/include \
 -I//homes/nikom/work/Java/jdk1.2/include/linux \
 -c HelloWorldImp.c \
 -o HelloWorldImp.o

Notice, you need to provide path to C include directory. 
It is not obvious thing to do.

my_directory>ls -l
HelloWorld.java
HelloWorld.class
HelloWorld.h
HelloWorldImp.c
HelloWorldImp.o

step 5b: creating the shared library
gcc -shared HelloWorldImp.o -o libhello.so

my_directory>ls -l
HelloWorld.java
HelloWorld.class
HelloWorld.h
HelloWorldImp.c
HelloWorldImp.o
libhello.so

step 6: Run the Program
java HelloWorld

Hello world!


Good luck,

Jacob Nikom


Justin Lawler wrote:
> 
> Hi all,
> 
> is there anywhere i can get information/documentation on using JNI on linux.
> I know you use the javah tool to create a header file for your c program, but
> where do you go from there.
> 
> any help much appreciated,
> 
> Justin.
> 
> ----------------------------------------------------------------------
> To UNSUBSCRIBE, email to [EMAIL PROTECTED]
> with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to