JNI + Solaris : LD_LIBRARY_PATH / java.library.path initialisation

Hello.

Some JNI tools have been built to run on both windows and Solaris.

For the windows part, The PATH has been modified to add the DLL in order to be able to load the library into the JVM.

After some hard time to get the DLL build process doing his job, finally every thing worked.

But in Solaris, I can't have the library loaded (of course the library is build on Solaris ; a so file).

In a shell I try to launch some unit testing but every tries failed.

I tried to log the value of java.library.path and it remains empty on Solaris.

I think it's the environment variable that is not set properly. But I don't know what's wrong.

Here is the shell :

...

[ -z"$MOTEUR_HOME" ] && MOTEUR_HOME=`pwd`

# d閒inition du r閜ertoire des archives

LIBDIR="$MOTEUR_HOME/lib"

...

# classe ?lancer

_main=org.junit.runner.JUnitCore

# tests ?lancer

_tests=fr.mediapost.itineraire.moteur.MoteurImplTest

# le r閜ertoire contenant les moteurs

_libpath="$MOTEUR_HOME/moteur"

#classpath

_CP=$MOTEUR_HOME:$MOTEUR_HOME/configuration:$LIBDIR

if [ -d"$LIBDIR" ]; then

for i in"$LIBDIR"/*.jar; do

_CP="$_CP":"$i"

done

fi

...

#echo CLASSPATH : $_CP

echo JAVA_HOME : $JAVA_HOME

echo MOTEUR_HOME : $MOTEUR_HOME

echo Moteur : $_libpath

LD_LIBRARY_PATH=$_libpath

export LD_LIBRARY_PATH

# lancement

$JAVA_HOME/bin/java -DMOTEUR_HOME=$MOTEUR_HOME -Djava.library.path=$_libpath -DLD_LIBRARY_PATH=$_libpath -cp $_CP $_main $_tests

The output is :

MOTEUR_HOME : /export/home/users/sylvain.mougenot/moteur

Moteur : /export/home/users/sylvain.mougenot/moteur/moteur

JUnit version 4.1

09:57:12,361 DEBUG [MoteurImplTest] testCalculerInterface() - java.library.path=

...

Caused by: java.lang.UnsatisfiedLinkError: no libMoteur in java.library.path

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

The libMoteur.so file is in the directory associated to the shell variable $_libpath.

Can someone tell me what I've to do to fix it?

Could the so file be found but Java can't load it?

Message was edited by:

SMougenot

[2527 byte] By [SMougenota] at [2007-11-26 16:03:21]
# 1

Some progress :

The library pat is displayed on the output (meaning that the directory containing the so file is in the java.library.path):

In the shell I removed the definition for environnement variable from the java command line :

LD_LIBRARY_PATH=$_libpath:$LD_LIBRARY_PATH

export LD_LIBRARY_PATH

...

$JAVA_HOME/bin/java -DMOTEUR_HOME=$MOTEUR_HOME -cp $_CP $_main $_tests

the output is now :

MOTEUR_HOME : /export/home/users/sylvain.mougenot/moteur

Moteur : /export/home/users/sylvain.mougenot/moteur/moteur

LD_LIBRARY_PATH : /export/home/users/sylvain.mougenot/moteur/moteur:/usr/lib:/usr/local/lib

JUnit version 4.1

.10:34:32,405 DEBUG [MoteurImplTest] testCalculerInterface() - java.library.path=/usr/jdk1.5.0_09/jre/lib/sparcv9/server:/usr/jdk1.5.0_09/jre/lib/sparcv9:/usr/jdk1.5.0_09/jre/../lib/sparcv9:[b]/export/home/users/sylvain.mougenot/moteur/moteur[/b]:/usr/lib:/usr/local/lib:/usr/lib

...

exception is java.lang.UnsatisfiedLinkError: no libMoteur in java.library.path

Caused by: java.lang.UnsatisfiedLinkError: no libMoteur in java.library.path

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

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

Please, could someone check the following build process for the so file :

g++ -shared -Wall -Wshadow -O2 -c -fPIC -ID:. -I/usr/jdk1.5.0_09/include -I/usr/jdk1.5.0_09/include/solaris ./InterfaceMoteur.cpp ./DllRecuit.cpp

ld -G *.o -o libMoteur.so

Message was edited by:

SMougenot

SMougenota at 2007-7-8 22:25:12 > top of Java-index,Java HotSpot Virtual Machine,Specifications...