熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

java smslib發送短信

2013-11-23 18:43:26  來源: Java核心技術 

  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(yUSB

  /dev/ttyUSB WAVECOM MODEM W);//采用Sony Ericsson的Wc手機發送

  gatewaysetProtocol(AGatewayProtocolsPDU);

  gatewaysetInbound(true);

  gatewaysetOutbound(true);

  gatewaysetSimPin();

  srvaddGateway(gateway);

  srvstartService();

  Systemoutprintln(Mobile Device Information: );

  Systemoutprintln( Manufacturer : + gatewaygetManufacturer());

  Systemoutprintln( Model : + gatewaygetModel());

  Systemoutprintln( Serial No : + gatewaygetSerialNo());

  Systemoutprintln( IMSI : + gatewaygetImsi());

  Systemoutprintln( S/W Version : + gatewaygetSwVersion());

  Systemoutprintln( Battery Level : + gatewaygetBatteryLevel() + %);

  Systemoutprintln( Signal Level : + gatewaygetSignalLevel() + %);

  msg = new OutboundMessage(phone content);

  srvsendMessage(msg);

  srvstopService();

  }

  public static void main(String args[]) throws IOException

  InterruptedException SMSLibException {

  SendMessage app = new SendMessage();

  appdoIt(****** Hello);

  }

  }

  運行: /usr/java/jre_/bin/java Dsmslibserialpolling classpath  logjjar:smslibjar testSendMessage

  出錯: Exception in thread main javalangNoClassDefFoundDrror: SendMessage

  後來終於找到原因: java加載了SendMessageclass以後java就試圖到CLASSPATH中找類SendMessageCLASSPATH為

  $CLASSPATH=/usr/java/jre_/lib:/usr/java/jre_/jre/lib

  java找不到SendMessage類的定義windows包含了當前路徑但是linux和unix沒有當前路徑必須手工添加

  /usr/java/jre_/bin/java Dsmslibserialpolling classpath  logjjar:smslibjar: testSendMessage

  注意最後加了一個冒號和點冒號是linux下文件分割符


From:http://tw.wingwit.com/Article/program/Java/hx/201311/25626.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.