Question

My Java program fails with the following error on Windows.

Exception in thread "main" java.lang.UnsatisfiedLinkError: no XSvcSocket in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)

I tried different things like

  • adding the location of DLL to system's path env variable
  • setting location of DLL explicitly in the program as below

            String libpath = System.getProperty("java.library.path");
            libpath = "C:\\extlibs;" + libpath;
            System.setProperty("java.library.path", libpath);
            libpath = System.getProperty("java.library.path");
    

java.library.path I get see is shown below.

"Lib Path: C:\extlibs;C:\Program Files\Java\jre6\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows"

The DLL in question is available in "C:\extlibs". Couple of observation are that when I place the DLL into "C:\Program Files\Java\jre6\bin", my program doesn't crib about the DLL (i.e it loads it) but I have to take care of many other DLLs too.

Can anyone shed some light on this behavior? by the way I am also not able to figure out from where eclipse is picking C:\Program Files\Java\jre6\bin and adding to java.library.path? it's not part of system's path environment variable.

Was it helpful?

Solution

The correct way to add native libraries in eclipse is as shown below. Go to Properties/Java Build Path/Libraries/Expand the jar file for which you want to add the native library/Select Native Library location/Click Edit/Add the DLL

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top