Java JNA 加载 DLL
Java JNA load DLL
当我尝试像这样加载 DLL 时遇到问题:
String a = "C:\Users\ElteGps 022\Documents\NetBeansProjects\JavaApplication1\src\lib\EQ2008_Dll.dll";
String strDllFileName = m_strUserPath + "\res\EQ2008_Dll.dll";
String strEQ2008_Dll_Set_Path = m_strUserPath + "\res\EQ2008_Dll_Set.ini";
m_DllLibrary = (DllLibrary) Native.loadLibrary(a,DllLibrary.class);
我看到了这个:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'C:\Users\ElteGps 022\Documents\NetBeansProjects\JavaApplication1\src\lib\EQ2008_Dll.dll': Nie mo¿na odnaleæ okrelonego modu³
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)
at javaapplication1.Fun.main(Fun.java:280)
我阅读并这样做了:
- giving 'java.library.path' in netbeans for .dll/.so files
Library Search Paths
A search for a given library will scan the following locations:
jna.library.path
User-customizable path
jna.platform.library.path
Platform-specific
paths - On OSX,
~/Library/Frameworks
,
/Library/Frameworks
, and
/System/Library/Frameworks
will be searched for a
framework with a name corresponding to that requested. Absolute
paths to frameworks are also accepted, either ending at the framework
name (sans ".framework") or the full path to the framework shared
library (e.g. CoreServices.framework/CoreServices).
- Context class loader classpath. Deployed native libraries
may be installed on the classpath under
${os-prefix}/LIBRARY_FILENAME
, where
${os-prefix}
is the OS/Arch prefix returned by Platform.getNativeLibraryResourcePrefix()
.
If bundled in a jar file, the resource will be extracted to
jna.tmpdir
for loading, and later removed (but only if
jna.nounpack
is false or not set).
You may
set the system property jna.debug_load=true
to make JNA
print the steps of its library search to the console.
Native.loadLibrary 不适用于完整路径,请尝试 System.load
如果你不能使用它,你也可以通过设置 java 的环境变量 java 在加载 之前指定 dll 的目录
System.setProperty("jna.library.path", "C:\Users\ElteGps 022\Documents\NetBeansProjects\JavaApplication1\src\lib");
但强烈不推荐这样做,因为它只能在您的计算机上运行
当我尝试像这样加载 DLL 时遇到问题:
String a = "C:\Users\ElteGps 022\Documents\NetBeansProjects\JavaApplication1\src\lib\EQ2008_Dll.dll";
String strDllFileName = m_strUserPath + "\res\EQ2008_Dll.dll";
String strEQ2008_Dll_Set_Path = m_strUserPath + "\res\EQ2008_Dll_Set.ini";
m_DllLibrary = (DllLibrary) Native.loadLibrary(a,DllLibrary.class);
我看到了这个:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'C:\Users\ElteGps 022\Documents\NetBeansProjects\JavaApplication1\src\lib\EQ2008_Dll.dll': Nie mo¿na odnaleæ okrelonego modu³
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)
at javaapplication1.Fun.main(Fun.java:280)
我阅读并这样做了:
- giving 'java.library.path' in netbeans for .dll/.so files
Library Search Paths A search for a given library will scan the following locations:You may set the system property
jna.library.path
User-customizable pathjna.platform.library.path
Platform-specific paths- On OSX,
~/Library/Frameworks
,/Library/Frameworks
, and/System/Library/Frameworks
will be searched for a framework with a name corresponding to that requested. Absolute paths to frameworks are also accepted, either ending at the framework name (sans ".framework") or the full path to the framework shared library (e.g. CoreServices.framework/CoreServices).- Context class loader classpath. Deployed native libraries may be installed on the classpath under
${os-prefix}/LIBRARY_FILENAME
, where${os-prefix}
is the OS/Arch prefix returned byPlatform.getNativeLibraryResourcePrefix()
. If bundled in a jar file, the resource will be extracted tojna.tmpdir
for loading, and later removed (but only ifjna.nounpack
is false or not set).jna.debug_load=true
to make JNA print the steps of its library search to the console.
Native.loadLibrary 不适用于完整路径,请尝试 System.load 如果你不能使用它,你也可以通过设置 java 的环境变量 java 在加载 之前指定 dll 的目录
System.setProperty("jna.library.path", "C:\Users\ElteGps 022\Documents\NetBeansProjects\JavaApplication1\src\lib");
但强烈不推荐这样做,因为它只能在您的计算机上运行