HELP: java.lang.UnsatisfiedLinkError: no ... in java.library.path

am the beginner of JNI. I write a test program to use C code in JAVA.

[yxz155@lionxo JAVAaC]$ ls

AClassWithNativeMethods.java theNativeMethod.c

[yxz155@lionxo JAVAaC]$ javac AClassWithNativeMethods.java

[yxz155@lionxo JAVAaC]$ javah -jni AClassWithNativeMethods

[yxz155@lionxo JAVAaC]$ ls

AClassWithNativeMethods.class AClassWithNativeMethods.java

AClassWithNativeMethods.h theNativeMethod.c

[yxz155@lionxo JAVAaC]$ gcc -c -fPIC -I/usr/global/java/include -I/usr/global/java/include/linux theNativeMethod.c

[yxz155@lionxo JAVAaC]$ ls

AClassWithNativeMethods.class AClassWithNativeMethods.java theNativeMethod.o

AClassWithNativeMethods.h theNativeMethod.c

[yxz155@lionxo JAVAaC]$ ld -G theNativeMethod.o -o libJCI.so -lm -lc -lpthread

[yxz155@lionxo JAVAaC]$ ls

AClassWithNativeMethods.class AClassWithNativeMethods.java theNativeMethod.c

AClassWithNativeMethods.h libJCI.so theNativeMethod.o

[yxz155@lionxo JAVAaC]$ java AClassWithNativeMethods

Exception in thread "main" java.lang.UnsatisfiedLinkError: no CJI 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 AClassWithNativeMethods.<clinit>(AClassWithNativeMethods.java:9)

[yxz155@lionxo JAVAaC]$

The codes are as follows, I tried setProperty() as in java program, but it did not work. I also tried set LD_LIBRARY_PATH and it did not work either.

//AClassWithNativeMethods.java

import java.io.File;

import java.lang.System;

public class AClassWithNativeMethods{

public native void theNativeMethod();

static {

//System.setProperty("java.library.path",System.getProperty("java.library.path")+ File.pathSeparator+"/home2/yxz155/JAVAaC");

//System.out.println(System.getProperty("java.library.path"));

System.loadLibrary("CJI");

}

public static void main(String[] args){

AClassWithNativeMethods test = new AClassWithNativeMethods ();

test.theNativeMethod();

}

}

// theNativeMethod.c

#include <stdio.h>

#include "AClassWithNativeMethods.h"

JNIEXPORT void JNICALL Java_AClassWithNativeMethods_theNativeMethod

(JNIEnv *env, jobject obj){

printf("Hello~~~~");

}

//AClassWithNativeMethods.h

/* DO NOT EDIT THIS FILE - it is machine generated */

#include <jni.h>

/* Header for class AClassWithNativeMethods */

#ifndef _Included_AClassWithNativeMethods

#define _Included_AClassWithNativeMethods

#ifdef __cplusplus

extern "C" {

#endif

/*

* Class: AClassWithNativeMethods

* Method: theNativeMethod

* Signature: ()V

*/

JNIEXPORT void JNICALL Java_AClassWithNativeMethods_theNativeMethod

(JNIEnv *, jobject);

#ifdef __cplusplus

}

#endif

#endif

[3031 byte] By [zhynxna] at [2007-11-26 16:35:56]
# 1

The answer to your problem is in the error stack.

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

java.library.path is a VM specific variable that can be set to point to libraries that Java loads. By default in windows it is set to path, on unix, I believe it is set to LD_LIBRARY_PATH. Uncommenting your println of

//System.out.println(System.getProperty("java.library.path"));

should tell you. If your library is not in that path, it will not be found.

you cand point to it by setting java.library.pth to point to the directory the library is in.

windows: -Djava.library.path= [dir of your library]

unix: LD_LIBRARY_PATH=[dir of your library]

if you want to append your library directory to the system value use:

windows: path=%path%;[dir of your library]

unix: LD_LIBRARY_PATH=$LD_LIBRARY_PATH:[dir of your library]

Jim

jjones3566a at 2007-7-8 23:00:49 > top of Java-index,Java HotSpot Virtual Machine,Specifications...