四川科技馆智能控制Java物联网AI开发
1.分清楚System.load与System.loadLibrary
System.load // System.load 参数必须为库文件的绝对路径,可以是任意路径,例如:System.load("C:\\Documents and Settings\\TestJNI.dll"); //Windows System.load("/usr/lib/TestJNI.so"); //Linux
System.loadLibrary //System.loadLibrary 参数为库文件名,不包含库文件的扩展名。System.loadLibrary ("TestJNI"); //加载Windows下的TestJNI.dll本地库 System.loadLibrary ("TestJNI"); //加载Linux下的libTestJNI.so本地库 //注意:TestJNI.dll 或 libTestJNI.so 必须是在JVM属性java.library.path所指向的路径中。
2.以上为原理(都不好使!!!)
GlobalFunction.getSingleton().loadJNILibrary("zlprint");
loadJNILibrary
这个炸天方法是自动从classpath或者jar包中寻找 zlprint.dll 或者 zlprint.so(具体根据OS系统平台决定)
重复加载相同的dll会报错哦!
loadJNILibrary要区分x86和x64,假设你有相同的两个zlprint.dll,请在前面加上目录限定名称,比如:windows-x86_64/zlprint
3.JavaCPP的坑
执行这些命令行的时候需要在Visual Studio