1

I am loading a library into my java code. I have put the library in the sytem 32 folder and I have also set the -Djava.library.path.

Earlier this code was running

try{


        System.loadLibrary("resources/TecJNI");

        System.out.println("JNI library loaded \n");
    }
    catch(UnsatisfiedLinkError e){
        System.out.println("Did not load library");
        e.printStackTrace();
    }

but since last week it is showing

java.lang.UnsatisfiedLinkError: no resources/TecJNI in java.library.path.

Is this some file permission issue for the dll that I am loading in the java code OR dll are using by some other application.

Also all other my running applications that were using & loading the same dll in different workspace are not running now.

Could anyone suggest me?

EDIT: I am using -

Djava.library.path="${workspace_loc}/org.syntec.ivb.application/resources;${env_var:PATH}"

in my eclipse vm arguments. I think it is using this.

3
  • loadLibrary expects a library name, whereas resources/TecJNI not really seems like a valid lib name. is 'resource' a directory in the system32 directory? Also how exactly do you define java.library.path? Commented Aug 13, 2013 at 8:05
  • I think I am using eclipse vm arguments settings. Not the system 32. I have updated the quesiton. Commented Aug 13, 2013 at 8:15
  • well then can you try using System.loadLibrary("TecJNI")? Commented Aug 13, 2013 at 8:19

3 Answers 3

2

when comes to load libs in jvm, I like to copy the libs to a temp directory, then load them from the temp directory. here is the code:

private synchronized static void loadLib(String dllPath,String libName) throws IOException {
    String osArch = System.getProperty("os.arch").contains("64")?"_X64":"_X86";
    String systemType = System.getProperty("os.name");
    String libExtension = (systemType.toLowerCase().indexOf("win") != -1) ? ".dll"
            : ".so";
    String libFullName = libName+osArch+ libExtension;
    String nativeTempDir = System.getProperty("java.io.tmpdir");

    InputStream in = null;
    BufferedInputStream reader = null;
    FileOutputStream writer = null;

    File extractedLibFile = new File(nativeTempDir + File.separator
            + libFullName);
    if (!extractedLibFile.exists()) {
        try {
            in = new FileInputStream(dllPath+ File.separator+
                    libFullName);
            reader = new BufferedInputStream(in);
            writer = new FileOutputStream(extractedLibFile);

            byte[] buffer = new byte[1024];

            while (reader.read(buffer) > 0) {
                writer.write(buffer);
                buffer = new byte[1024];
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (in != null)
                in.close();
            if (writer != null)
                writer.close();
        }
    }
    System.load(extractedLibFile.toString());
}
Sign up to request clarification or add additional context in comments.

1 Comment

nice way. I will definitely try it out. +1
1

System.loadLibrary expects library name, not a path. The path to the directory containg the library should be set in PATH (Windows) env variable or in -Djava.library.path

4 Comments

I am using -Djava.library.path="${workspace_loc}/org.syntec.ivb.application/resources;${env_var:PATH}" in my eclipse vm arguments. I think it is using this.
thanks. now its running smoothly. But dont know same configuration was running fine. I was having dll in the resources folder and by using -Djava.library.path="${workspace_loc}/org.syntec.ivb.application/resources;${env‌​_var:PATH}" it was picking up the library. Now I am using -Djava.library.path="C:/Windows/System32" and System.loadLibrary("TecJNI")
actually C:/Windows/System32 is supposed to be in Windows PATH, try without -Djava.library.path="C:/Windows/System32"
@arun It is a poor practice to put application files into system folders. It should be quite easy to avoid. The Eclipse IDE that you are using uses native libraries for SWT and it runs fine after just being unzipped.
1

Why do you need the additional "resources"?

When using System.loadLibrary("resources/TecJNI"); you are looking for TecJNI.dll in a subfolder "resources" of the java.library.path. So if you put C:\windows\system32 on the library-path (which you wouldn't need since it's on the search-path by default) your library should be C:\windows\system32\resources\TecJNI.dll

1 Comment

I am using -Djava.library.path="${workspace_loc}/org.syntec.ivb.application/resources;${env_var:PATH}" in my eclipse vm arguments. I think it is using this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.