jar包在windows正常执行,在linux执行报错

开发一个蓝牙扫描的demo,需要依赖 bluecove-2.1.1.jar
window能正常执行,linux报错

代码

import javax.bluetooth.*;
public class TestBlueTooth {
    public static void main(String[] args) throws Exception {
        //初始化本地设备
        //获取本地蓝牙适配器
        LocalDevice localDevice = LocalDevice.getLocalDevice();
        //设置设备可见性
        localDevice.setDiscoverable(DiscoveryAgent.GIAC);
        //获取本地设备地址
        String bluetoothAddress = localDevice.getBluetoothAddress();
        System.out.println("本地蓝牙地址:"+bluetoothAddress);
        System.out.println("开启蓝牙扫描");
        //启动设备发现
        DiscoveryAgent agent = localDevice.getDiscoveryAgent();
        TestDeviceListener testDeviceListener = new TestDeviceListener();
        agent.startInquiry(DiscoveryAgent.GIAC,testDeviceListener);
        //等待蓝牙扫描
        System.out.println("等待蓝牙扫描30s......");
        Thread.sleep(30000);
        agent.cancelInquiry(testDeviceListener);
    }
}

import javax.bluetooth.DeviceClass;
import javax.bluetooth.DiscoveryListener;
import javax.bluetooth.RemoteDevice;
import javax.bluetooth.ServiceRecord;
import java.io.IOException;

public class TestDeviceListener implements DiscoveryListener {
    //发现设备
    @Override
    public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
        String name = null;
        try {
            name = btDevice.getFriendlyName(false);
        } catch (IOException e) {
            e.printStackTrace();
        }
        String address = btDevice.getBluetoothAddress();
        System.out.println("发现设备: "+name+"  ("+address+")");
    }
    //服务搜索完成
    @Override
    public void servicesDiscovered(int i, ServiceRecord[] serviceRecords) {

    }
    //服务搜索完成
    @Override
    public void serviceSearchCompleted(int i, int i1) {

    }
    //设备发现完成
    @Override
    public void inquiryCompleted(int i) {
        System.out.println("设备发现完成");
    }
}

报错
在这里插入图片描述
检查BlueZ 是已经有的
在这里插入图片描述
查找系统上是否存在 libbluetooth.so 这个库文件

find / -name libbluetooth.so* 2>/dev/null

是有这个文件的
在这里插入图片描述
将这个库链接到 /usr/lib/ 目录下 再运行就可以了

sudo ln -s /usr/lib/x86_64-linux-gnu/libbluetooth.so.3 /usr/lib/libbluetooth.so

总结:库文件没有被正确引用导致的报错

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值