Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

java - javax.usb.UsbException: Properties file javax.usb.properties not found

I used the following code to get the manufacturerCode of the usb device attached to the system. I added the jsr80-1.0.1 jar. And I got the following error javax.usb.UsbException:

Properties file javax.usb.properties not found.

Any suggestions?

import java.io.UnsupportedEncodingException;
    import java.util.*;
    import javax.usb.*;

    public class USBListener {
        public static void main(String[] args) {
            try{
                UsbServices services = UsbHostManager.getUsbServices();
                UsbHub root = services.getRootUsbHub();
                listDevices(root);
            } catch (Exception e) {
                System.out.println(e);
            }
        }

        public static void listDevices(UsbHub hub) throws UnsupportedEncodingException, UsbException {
            List devices = hub.getAttachedUsbDevices();
            Iterator iterator = devices.iterator();
            while(iterator.hasNext()) {
                UsbDevice device = (UsbDevice)iterator.next();
                describe(device);
                if(device.isUsbHub()) {
                    System.out.println("is hub");
                }
            }
        }

        public static void describe(UsbDevice device) 
            throws UnsupportedEncodingException, UsbException {
            UsbDeviceDescriptor descriptor = device.getUsbDeviceDescriptor();
            byte manufacturerCode = descriptor.iManufacturer();
            System.out.println("Manufacturer index: " + manufacturerCode);
            System.out.println("Manufacturer String: " + device.getString(manufacturerCode));
            System.out.println("USB version: " + decodeBCD(descriptor.bcdUSB()));
            System.out.println("Maximum control packet size: " + descriptor.bMaxPacketSize0());

        }

        public static String decodeBCD(short bcd) {
            int upper = (0xFF00 & bcd) >> 8;
            int middle = (0xF0 & bcd) >> 4;
            int lower = 0x0F & bcd;
            return upper + "." + middle + "." + lower;
        }
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need this file on your classpath. From the docs:

The javax.usb.properties file is a Java properties file that is required by the API implementation loader class. The properties file must be loadable by normal means (i.e. it must be in the CLASSPATH) and it must contain the property javax.usb.services. This property must be defined. Its value must be the fully qualified class name of a class that implements the interface javax.usb.UsbServices. This class will be loaded as the implementation of javax.usb.

And further, if you are seeing this error, you presumably haven't got a javax.usb implementation:

You need a javax.usb implementation; the file is provided by all javax.usb implementations

See here: http://javax-usb.sourceforge.net/faq.html#what_is_properties_file


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...