Why does the first example work, but the second one doesn't?

HI,

slight problem that I can not seem to find the answer too. Example 1 below works OK, but example two gives me a UnspecifiedLinkError: displayHelloWorld. They both access the same the class (the 3rd listed), which then access the JNI (c++) file that talks to a win32 dll.

Example 1, runs a stand alone application, while Example two extends a class, implements a few other classes, and as its name suggests is a plugin to a larger application

Why doesn't this work?

Thanks

Mark

//////////////////////////////

Example 1

///////////////////////////////

package com.ii.svr.qas;

public class test {

public static void main (String args[]) {

QASAddressChecker qas = new QASAddressChecker();

qas.test();

}

}

/////////////////////////////

Example Two

/////////////////////////////

package com.ii.svr.qas;

public class QASPlugin {

public QASPlugin() {

Test();

}

private Test() {

QASAddressChecker qas = new QASAddressChecker();

qas.test();

}

///////////////////////////////

/* This class is the one called by both the examples above */

///////////////////////////////

package com.ii.svr.qas;

import java.io.*;

public class QASAddressChecker {

public native String displayHelloWorld();

public QASAddressChecker() {

System.loadLibrary ("hello");

}

public String test() {

String result = displayHelloWorld();

System.out.println(result);

return result;

}

}

///////////////////////////

End of examples

////////////////////////////

[1714 byte] By [Lemming] at [2007-9-26 13:15:08]
# 1

I think that your problem comes from the java VM environnement variable (the one you define with -D at launch time) that defines where libraries should be searched (something like LD_LIBRARY_PATH on Unix)

This is the kind of context that changes from a stand-alone program (where you can do what you want, and where default values aren't too dumb) to a pluggable exec environnement (where values can be, say, different..., and at least more difficult to change)

the var name is java.library.path

check it with something like System.out.println(System.getProperties());

cdore at 2007-7-2 13:21:52 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
Thanks for your comments,but I have already ensured that both examples are runnning in the same JVM, and are pointing to all the same files. I run both examples from the same command prompt, at the same location on my hard-disk.Thanks anywayMark
Lemming at 2007-7-2 13:21:52 > top of Java-index,Java HotSpot Virtual Machine,Specifications...