【发布时间】:2015-10-14 19:22:33
【问题描述】:
我目前正在为一个项目工作,我需要检测是否插入了 Oculus 设备。
我使用 usb4java 库 usb4java 这样做。
<dependency>
<groupId>org.usb4java</groupId>
<artifactId>usb4java-javax</artifactId>
<version>1.2.0</version>
</dependency>
我想使用安装在 ubuntu 服务器上的 Maven 和 Jenkins 构建我的程序,但是我遇到了这个库的问题:如果我的程序是使用这台机器构建的,我的功能不起作用,但是如果我在 Windows 上编译它,我的功能就像一个魅力。
这是我使用的功能:
if (hub == null) {
UsbServices services = UsbHostManager.getUsbServices();
hub = services.getRootUsbHub();
}
//List all the USBs attached
List devices = hub.getAttachedUsbDevices();
Iterator iterator = devices.iterator();
boolean res = false;
while (iterator.hasNext()) {
UsbDevice device = (UsbDevice) iterator.next();
UsbDeviceDescriptor desc = device.getUsbDeviceDescriptor();
if (device.isUsbHub()) {
res = res || isOculusPlugged((UsbHub) device);
}
else {
try {
if (desc.idVendor() == 10291) {
res = true;
}
} catch (NullPointerException ignored) {}
}
}
我没有得到任何错误,但是检测在 linux 构建的版本中不起作用(res 总是错误的)。
我检查了所有 JNI 库,包括 Windows 都在我正在运行的 JAR-With-Dependencies 中。
感谢您的帮助, 卢卡斯
【问题讨论】:
-
你试过jusb吗? stackoverflow.com/questions/13450673/…
标签: java maven jenkins java-native-interface usb4java