File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other JSE/JEE APIs and the fly likes JNI Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "JNI Error" Watch "JNI Error" New topic

JNI Error

Aashiq Babu

Joined: Mar 23, 2006
Posts: 1
An error in creating JNI

This is my java file and i have created the header file HelloNative.j using the commang javah -jni HelloNative. Below is the header file

class HelloNative
{ public static native void greeting();
{ System.loadLibrary("greeting");

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class HelloWorld */

#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
extern "C" {
* Class: HelloWorld
* Method: hello
* Signature: (Ljava/lang/String V
JNIEXPORT void JNICALL Java_HelloWorld_hello
(JNIEnv *, jobject, jstring);

#ifdef __cplusplus

I have included the header file which was created above

#include "HelloNative.h"
#include <stdio.h>
#include <jni.h>
JNIEXPORT void JNICALL Java_HelloNative_greeting
(JNIEnv* env, jclass cl)
{ printf("Hello world!\n");

class HelloNativeTest
{ public static void main(String[] args)
{ HelloNative.greeting();

i have complied the C file using
cc HelloNative.c -I$JAVA_HOME/include -I$JAVA_HOME/include/linux -shared -fpic -o

I have created the to call the C function and when i compile i am getting the error

java HelloNativeTest
Exception in thread "main" java.lang.UnsatisfiedLinkError: no greeting in java.l
at java.lang.ClassLoader.loadLibrary(
at java.lang.Runtime.loadLibrary0(
at java.lang.System.loadLibrary(
at HelloNative.<clinit>(

I am getting this error. I have set the LD_LIBRARY_PATH as follows


Pls help me to slove this problem
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Well, you did System.loadLibrary("greeting"), but your compilation made a shared library called "". That's not going to work. You need to get the name of your shared library right. I can't remember exactly how they're named on Linux, but it's going to be something with "greeting" in the name. Maybe ""?

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Peter's advice is spot on.

Moving to "Other Java APIs", where JNI questions go.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: JNI Error
It's not a secret anymore!