0

I am running 64 windows. My java version says:

java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

My project is GWT Spring project ran on Apache Tomcat server, above java properties apply to the server (this is said to clarify that the server isn't accidentally running different Java version).

In Java code, I use System.getProperty("sun.arch.data.model") to determine Java version and based on result, I load either 64 or 32 bit dll. In the specific case, I'm now running 64bit and therefore I need 64bit dll file. I placed the file in this location:

D:\programs\apache-tomcat-7.0.64-windows-x64\webapps\war\WEB-INF\lib\MY_LIBRARYx64.dll

In the java code, I have this function to load the library:

private void setLibraryPath_private(String libraryPath) {

    // Some magic which doesn't work anyway
    File path = new File(configService.getProjectPrefix() + libraryPath);


    try {
        // Get valid canonical path (special case of absolute path)
        path = new File(path.getCanonicalPath());
        // Check for readability of that location
        if(!path.canRead())
            throw new IOException("Cannot read from this file.");
    }
    catch(IOException e) {
        logger.error("Invalid path to R220 library: "+path.getAbsolutePath(), e);
    }

    // Remember path as string
    this.libraryPath = path.getAbsolutePath();
    try {
        // Load it
        library =
        (R220) Native.loadLibrary(path.getCanonicalPath(), R220.class);
    }
    catch(Throwable e) {
        // TODO: After loading problem is solved, probably replace throw with the logging
        //logger.error("Failed to load R220 library: "+path.getAbsolutePath(), e);          
        throw new IllegalArgumentException("Failed to load R220 library: "+path.getAbsolutePath(), e);
    }
    // I don't know what this is
    library.initLogger(configService.getLog4cplusConfigFilePath()); 
}

But in my log I still get error:

[INFO ] 2015-09-21 15:52:26,038 cz.techsys.web.server.R220LibService - Running 64bit version of the native libary.
[ERROR] 2015-09-21 15:52:26,113 cz.techsys.web.server.R220LibService - Failed to load R220 library: D:\programs\apache-tomcat-7.0.64-windows-x64\webapps\war\WEB-INF\lib\MY_LIBRARYx64.dll
java.lang.UnsatisfiedLinkError: Unable to load library 'D:\programs\apache-tomcat-7.0.64-windows-x64\webapps\war\WEB-INF\lib\MY_LIBRARYx64.dll': The specified module could not be found.

    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:163)
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:236)
    at com.sun.jna.Library$Handler.<init>(Library.java:140)
    at com.sun.jna.Native.loadLibrary(Native.java:379)
    at com.sun.jna.Native.loadLibrary(Native.java:364)

I also checked whether my library really is 64bit. It is, according to this guy:

image description

I also compared it to the 32bit version, which looks like this:

image description

So to sum up:

  • Processor architecture matches for the library and Java
  • The library is in readable and reachable location

What else can be causing the trouble?

Edit: Based on some comments here, I also tried to pass library name without extension and set library path through System:

    // Remove name from extension
    String name = path.getName().replaceFirst("[.][^.]+$", "");
    // Get directory path
    String dir = path.getParentFile().getAbsolutePath();
    // Print path to console for debug
    logger.warn("\n       Lib path: "+dir+"\n       Lib name:"+name);
    // Change library path
    System.setProperty("jna.library.path", dir);
    // Load it
    library =
    (R220) Native.loadLibrary(name, R220.class);

Needless to say, this had no effect, except the one that error message is now slightly shorter:

[WARN ] 2015-09-21 16:33:56,819 cz.techsys.web.server.R220LibService - 
       Lib path: D:\programs\apache-tomcat-7.0.64-windows-x64\webapps\war\WEB-INF\lib
       Lib name:WebSightR220libx64
[ERROR] 2015-09-21 16:33:56,882 cz.techsys.web.server.R220LibService - Failed to load R220 library: D:\programs\apache-tomcat-7.0.64-windows-x64\webapps\war\WEB-INF\lib\WebSightR220libx64.dll
java.lang.UnsatisfiedLinkError: Unable to load library 'WebSightR220libx64': The specified module could not be found.

    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:163)
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:236)
Community
  • 1
  • 1
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
  • http://stackoverflow.com/a/6824337/3166303 – leeor Sep 21 '15 at 14:09
  • you added `.dll` to library name? – Jordi Castilla Sep 21 '15 at 14:11
  • 2
    The library is not in a reachable location, local libraries can't be reached from WEB-INF/lib; they must be read by the native linker. LD_LIBRARY_PATH or (on Windows) PATH. – Elliott Frisch Sep 21 '15 at 14:11
  • http://stackoverflow.com/questions/14286647/trying-to-use-dll-from-java-jna-unable-to-load-library-exception – Jordi Castilla Sep 21 '15 at 14:13
  • I don't understand. Why can't I load library on any absolute path? Anyway, I tried it - I used `System.setProperty("java.library.path", dir);` and I passed library name without extension. It still doesn't work. – Tomáš Zato Sep 21 '15 at 14:32
  • You may need to use `Native.extractFromResourcePath()` to ensure the DLL actually exists on the filesystem in a form it can be loaded. Normally the OS can't load a shared library if it's within an archive (JAR, WAR, or otherwise). – technomage Sep 21 '15 at 16:23

0 Answers0