Roland85
Roland85

Reputation: 31

jna load library

i'm having a problem on loading a dll with jna. While i can debug the code within eclipse, i get an Exception when i export and run it as a jar file:

java.lang.UnsatisfiedLinkError: unable to load library 'SiUSBXp'

Any ideas why it does not find my dll when i run it as a jar-file?

Thanks!!!!

public interface SiUSBXp extends StdCallLibrary {
    byte SI_GetNumDevices(IntByReference numdevices);
    byte SI_GetProductString( int deviceNum, byte[] productString, int options );
    byte SI_Open(IntByReference numdevices);
}

static SiUSBXp INSTANCE;

public static void main(String[] args) {
    System.setProperty("jna.library.path","SiUSBXp.dll");
    HashMap<String, StdCallFunctionMapper> optionMap = new HashMap<String, StdCallFunctionMapper>();
    StdCallFunctionMapper myMapper = new StdCallFunctionMapper();
    optionMap.put(Library.OPTION_FUNCTION_MAPPER, myMapper);
    INSTANCE = (SiUSBXp) Native.loadLibrary("SiUSBXp", SiUSBXp.class, optionMap);
}

------------------ EDIT ----------------------

The dll is located in the same folder as the jar is

------------------ EDIT 2 ---------------------

I've just tried to run it within windows xp and it works .. but it does not within windows 7 (64 bit)

------------------ EDIT 3 --------------------- I've solved the problem ... It was due to the java versions installed ... I removed them all, and then only installed the x86 version of java ... after that it worked perfectly

Upvotes: 2

Views: 12360

Answers (1)

chance
chance

Reputation: 6487

Put the DLL into the "Current Folder" or system variable PATH, or use -Djna.library.path=(path to the dll) as VM switch instead of hard-coding.

Upvotes: 5

Related Questions