loadometer.dll 文件名称 dll放在resources中
package com.weighbridge.util;
import com.sun.jna.Library;
import com.sun.jna.Native;
public abstract interface JnaLibrary
extends Library
{
public static final JnaLibrary INSTANCE = (JnaLibrary)Native.load("loadometer", JnaLibrary.class);
public abstract double getWeight(String paramString, int paramInt);
}
package com.weighbridge.test;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.sun.jna.Native;
import com.weighbridge.util.DownloadPdf;
import com.weighbridge.util.JnaLibrary;
@RestController
public class WeighbridgeController {
public static final JnaLibrary INSTANCE = (JnaLibrary)Native.load("loadometer", JnaLibrary.class);
@RequestMapping(value = "/getWeighbridge")
@ResponseBody
public double test() {
double weight = INSTANCE.getWeight("Pon", 3);
return weight;
}
}
这里碰到一个问题 dll 是32位系统的文件 ,但是测试的电脑是 64位的 jdk也是64位的无法测试 提示: “不是有效的 Win32 应用程序”
解决办法是:java调用时 用32位的jdk 去测试就可以成功调用了
总结: java 调用dll 时 系统版本 64位dll 对应 64位的jdk 32位dll 对应32位jdk
https://blog.csdn.net/u014104286/article/details/53391394 参考博客