Search code examples
javajarjna

Exception in thread "main" java.lang.UnsatisfiedLinkError: jnidispatch (/com/sun /jna/win32-x86/jnidispatch.dll) not found in resource path


I have a small test program which runs perfectly in the JBuilder 6 debugger. When I make a .jar file and run it I get an error

>java -jar testadll.jar
Start of DLL test
Exception in thread "main" java.lang.UnsatisfiedLinkError: jnidispatch (/com/sun
/jna/win32-x86/jnidispatch.dll) not found in resource path
    at com.sun.jna.Native.loadNativeLibraryFromJar(Native.java:708)
    at com.sun.jna.Native.loadNativeLibrary(Native.java:685)
    at com.sun.jna.Native.<clinit>(Native.java:109)
    at testadll.TestThisDLL$PenniesLib.<clinit>(TestThisDLL.java:24)
    at testadll.TestThisDLL.main(TestThisDLL.java:33)

I have searched my drive and there is no jnidispatch.dll on it.

The program is

package testadll;

import com.sun.jna.Library;
import com.sun.jna.Native;
//import com.sun.jna.NativeLong;
import com.sun.jna.Platform;
import com.sun.jna.win32.StdCallLibrary;
//import com.sun.jna.*;



public class TestThisDLL {
   public interface PenniesLib extends StdCallLibrary {
    PenniesLib INSTANCE = (PenniesLib) Native.loadLibrary(
            "PenniesLib", PenniesLib.class);
        int a();
    }

  public static void main( String args[] ) {
      System.out.println("Start of DLL test");
      //TestDLL t = new TestDLL();
      //System.out.println("DLL loaded");
      int value = PenniesLib.INSTANCE.a();
      System.out.println("DLL response is " + String.valueOf(value));
  }
}

Solution

  • You've apparently merged JNA's classes with your own jar file, but omitted its native support. Ensure that all files from the original jna.jar (not just class files) are copied to the new destination and that their original paths are preserved.

    Specifically, your jar file must include com/sun/jna/win32-x86/jnidispatch.dll. If you want to include support for other platforms, you must include com/sun/jna/*/jnidispatch as well.