java smslib发送短信

public class SendMessage {
    public void doIt(String phone, String content) throws IOException,
            InterruptedException, SMSLibException {
        Service srv;
        OutboundMessage msg;
        srv = new Service();
        SerialModemGateway gateway = new SerialModemGateway("modem.ttyUSB0",
                "/dev/ttyUSB0", 9600, "WAVECOM MODEM", "W810");//采用Sony Ericsson的W810c手机发送
        gateway.setProtocol(AGateway.Protocols.PDU);
        gateway.setInbound(true);
        gateway.setOutbound(true);
        gateway.setSimPin("0000");
        srv.addGateway(gateway);
        srv.startService();
        System.out.println("Mobile Device Information: ");
        System.out.println(" Manufacturer : " + gateway.getManufacturer());
        System.out.println(" Model : " + gateway.getModel());
        System.out.println(" Serial No : " + gateway.getSerialNo());
        System.out.println(" IMSI : " + gateway.getImsi());
        System.out.println(" S/W Version : " + gateway.getSwVersion());
        System.out.println(" Battery Level : " + gateway.getBatteryLevel() + "%");
        System.out.println(" Signal Level : " + gateway.getSignalLevel() + "%");
        msg = new OutboundMessage(phone, content);
        srv.sendMessage(msg);


        srv.stopService();
    }

    public static void main(String args[]) throws IOException,
            InterruptedException, SMSLibException {
        SendMessage app = new SendMessage();

        app.doIt("136******", "Hello");


    }
}

运行: /usr/java/jre1.6.0_13/bin/java -Dsmslib.serial.polling -classpath  log4j-1.2.15.jar:smslib-3.4.6.jar test.SendMessage
出错: Exception in thread "main" java.lang.NoClassDefFoundDrror: SendMessage

后来终于找到原因: java加载了SendMessage.class以后,java就试图到CLASSPATH中找类SendMessage,CLASSPATH为:
$CLASSPATH=/usr/java/jre1.6.0_13/lib:/usr/java/jre1.6.0_13/jre/lib
java找不到SendMessage类的定义。windows包含了当前路径,但是linux和unix没有当前路径,必须手工添加
/usr/java/jre1.6.0_13/bin/java -Dsmslib.serial.polling -classpath  log4j-1.2.15.jar:smslib-3.4.6.jar:. test.SendMessage
注意最后加了一个冒号和点,冒号是linux下文件分割符。

你可能感兴趣的:(java,linux,log4j,mobile,windows phone)