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

旧时模样 提交于 2019-12-20 03:27:08

问题


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));
  }
}

回答1:


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.




回答2:


You should use a version of jna.jar, that supports 64 bit, for example jna-4.1.0.jar or jna-3.4.0.jar.



来源:https://stackoverflow.com/questions/17346438/exception-in-thread-main-java-lang-unsatisfiedlinkerror-jnidispatch-com-sun

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!