Java Native InterfaceTo Compile and RunThe most recent copy of the code is in: For JNI:In order to run the JNI code the class view team has developed so far, you will need to complete the following steps.
First of all, add the following lines to your This will ensure that you have the proper java path and that you can access your directory from anywhere (useful when looking at other code). Second, add the following: The LD_LIBRARY_PATH is the shared library path, libcomm.so (if you use our makefile).
The SGI_ABI is a sgi specific environment field.
The THREADS_FLAG makes sure that the java compiles with native threads, not green.
All the .c, .h, .java files will need to be copied into a directory if you want to compile this. Also, copy build and Makefile. You should only have to change the SLINK variable to your working path. The command by command I use is: and to run:
Here are step by step instructions for compiling a helloworld JNI app:
http://java.sun.com/docs/books/tutorial/native1.1/stepbystep/index.html
In a nutshell, here are the steps for adding in a new module for JNI. Use the web pages as reference.
WRITE THE JAVA:
Create any functions you want to call into C with the following syntax:
These should go before the constructor, and are actually just prototypes.
COMPILE CODE AND HEADERS:
Use javac to compile your java code.
On all classes with a system.load call, do the following:
NOTE: there is no .class or .java after it, it's not a mistake.
DO NOTE EDIT THIS .H FILE!!!!
WRITE THE C FILE AND CREATE A SHARED LIBRARY:
The syntax for any function called with JNI is:
The rest of the module is straight C unless you are using JNI specific calls to tie into something special in the Java.
Creating the shared library varies from system to system. For the SGI version, look at the makefile in the same directory as the helloworld application from above. I would sugguest using a makefile as it gets very tedious to compile it. For other operating systems, refer to step five of the JNI tutorial or that O/S's homepage.
RUN IT:
and watch it go.
If you get an UnsatisfiedLink error, one of 3 things happened:
|