硬件是短信猫一个,COM口用超级终端可以发送成功及用相关软件也能发送成功。可在放在myEclipse中出错。已做了环境的配置,在smslib\dist\lib目录下找到smslib-3.3.0b2.jar,放入工程lib中,再把javacomm20-win32.zip解开,里面的comm.jar需要放到工程lib下,javax.comm.properties放到%JAVA_HOME%/jre/lib下,win32com.dll放到%JAVA_HOME%/jre/bin下,具体代码如下:
import org.smslib.IOutboundMessageNotification;
import org.smslib.Library;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.Message.MessageEncodings;
import org.smslib.modem.SerialModemGateway;public class SendMessage
{
public void doIt() throws Exception
{
Service srv;
OutboundMessage msg;
OutboundNotification outboundNotification = new OutboundNotification();
        srv = new Service();
SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM1", 9600, "wavecom", "17254");//115200是波特率,一般为9600。可以通过超级终端测试出来
gateway.setInbound(true);
gateway.setOutbound(true);
gateway.setSimPin("0000");
gateway.setOutboundNotification(outboundNotification);
srv.addGateway(gateway);
srv.startService();
    msg = new OutboundMessage("13418687205", "这个是用java发的中文短信!");
msg.setEncoding(MessageEncodings.ENCUCS2);//这句话是发中文短信必须的
srv.sendMessage(msg);
System.out.println("Now Sleeping - Hit <enter> to terminate.");
System.in.read();
srv.stopService();
} public class OutboundNotification implements IOutboundMessageNotification
{
public void process(String gatewayId, OutboundMessage msg)
{
System.out.println("Outbound handler called from Gateway: " + gatewayId);
System.out.println(msg);
}
} public static void main(String args[])
{
SendMessage app = new SendMessage();
try
{
app.doIt();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}报如下错误:org.smslib.GatewayException: Comm library exception: java.lang.reflect.InvocationTargetException
at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:93)
at org.smslib.modem.AModemDriver.connect(AModemDriver.java:106)
at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:111)
at org.smslib.Service$1Starter.run(Service.java:227)

解决方案 »

  1.   

    有人说是JDK的问题目,我开始JDK用的1.4后来换的1.5还是出这样的问题,请高手指教。我也不知错在哪里,网上大部份人都说是这样的,唉,在线等,等
      

  2.   

    再补充下,我的classpath中已添加了comm.jar,这是我的classpath:D:\Program Files\Java\jdk1.5.0_04\bin;C:\Documents and Settings\Administrator\workspace\Pod\WebRoot\WEB-INF\lib\axis.jar;C:\Documents and Settings\Administrator\workspace\Pod\WebRoot\WEB-INF\lib\commons-discovery-0.2.jar;C:\Documents and Settings\Administrator\workspace\Pod\WebRoot\WEB-INF\lib\commons-discovery.jar;C:\Documents and Settings\Administrator\workspace\Pod\WebRoot\WEB-INF\lib\commons-logging-1.0.4.jar;C:\Documents and Settings\Administrator\workspace\Pod\WebRoot\WEB-INF\lib\jaxrpc.jar;C:\Documents and Settings\Administrator\workspace\Pod\WebRoot\WEB-INF\lib\log4j-1.2.8.jar;C:\Documents and Settings\Administrator\workspace\Pod\WebRoot\WEB-INF\lib\saaj.jar;C:\Documents and Settings\Administrator\workspace\Pod\WebRoot\WEB-INF\lib\wsdl4j-1.5.1.jar;C:\Documents and Settings\Administrator\workspace\Pod\WebRoot\WEB-INF\lib\classes12.jar;C:\Documents and Settings\Administrator\workspace\Pod\WebRoot\WEB-INF\lib\javaee.jar;%JAVA_HOME%\lib\activation.jar;%JAVA_HOME%\lib\mail.jar;D:\Program Files\Java\jdk1.5.0_04\lib\commons-net-1.4.1.jar;D:\Program Files\Java\jdk1.5.0_04\jre\lib\ext\comm.jar;
      

  3.   

    jdk换1.6再试试看,感觉你java环境变量设置很乱,呵
      

  4.   

    看情况像是comm.jar的问题,看看是不是JAR损坏或者是版本不对.
      

  5.   

    这个问题我暂时还没解决呢,我也是想做成你说的在WEB中添加发短短信功能。如果成功了我会贴出结果。谢谢你关注
      

  6.   

    会不会是你的myeclipse里的路径配置问题?你用myeclipse里面自带的配置试试~~~
      

  7.   


       短信猫便宜点 的 几百块, 贵一点的 几千都有, 配置在网站服务器上即可用, 猫只是一个 GSM Modem , 具体还是要通过移动来发送, 里面需要插入 sim    卡。 成本跟你手机发送短信一样。 发送成功在返回对象中有个 send ,为 true 则表示成功, false 则表示失败。
        楼主 , 你的问题解决没?  我已经也遇到过这样的问题。 
      

  8.   


      这个貌似和Eclipse 的配置没关系, 我忘了以前是怎么解决的, 让我想下啊 , 嘿嘿。。
      

  9.   


      你检查下javax.comm.properties放到%JAVA_HOME%/jre/lib下,win32com.dll放到%JAVA_HOME%/jre/bin下。smslib-3.3.0b2.jar和comm.jar,是  否放入工程lib中。  commons-net-1.4.1.jar 包你已经加到工程中去了。 再在你的工程中加入 commons-lang-2.4.jar  这个包试试。
      

  10.   

    我也遇到了问题。我用的是JRE1.6,下载的smslib是3.3.3,
    在用里面的ReadMessages的例子时,运行到this.srv = new Service();时就跳过去了,我跟踪了一下,SRV没有创建成功,
    请客各位高手是为什么?代码如下:package MainPackage;import java.util.ArrayList;
    import java.util.List;
    import org.smslib.ICallNotification;
    import org.smslib.IGatewayStatusNotification;
    import org.smslib.IInboundMessageNotification;
    import org.smslib.InboundMessage;
    import org.smslib.Library;
    import org.smslib.Service;
    import org.smslib.AGateway.GatewayStatuses;
    import org.smslib.AGateway.Protocols;
    import org.smslib.InboundMessage.MessageClasses;
    import org.smslib.Message.MessageTypes;
    import org.smslib.modem.SerialModemGateway;public class ReadMessages
    {
    Service srv; public void doIt() throws Exception
    {
    // Define a list which will hold the read messages.
    List<InboundMessage> msgList; // Create the notification callback method for inbound & status report
    // messages.
    InboundNotification inboundNotification = new InboundNotification(); // Create the notification callback method for inbound voice calls.
    CallNotification callNotification = new CallNotification(); //Create the notification callback method for gateway statuses.
    GatewayStatusNotification statusNotification = new GatewayStatusNotification(); try
    {
    //System.out.println("Example: Read messages from a serial gsm modem.");
    //System.out.println(Library.getLibraryDescription());
    //System.out.println("Version: " + Library.getLibraryVersion()); // Create new Service object - the parent of all and the main interface
    // to you.
    this.srv = new Service(); // Create the Gateway representing the serial GSM modem.
    SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM1", 57600, "Nokia", ""); // Set the modem protocol to PDU (alternative is TEXT). PDU is the default, anyway...
    gateway.setProtocol(Protocols.PDU); // Do we want the Gateway to be used for Inbound messages?
    gateway.setInbound(true); // Do we want the Gateway to be used for Outbound messages?
    gateway.setOutbound(true); // Let SMSLib know which is the SIM PIN.
    gateway.setSimPin("0000"); // Set up the notification methods.
    this.srv.setInboundNotification(inboundNotification);
    this.srv.setCallNotification(callNotification);
    this.srv.setGatewayStatusNotification(statusNotification); // Add the Gateway to the Service object.
    this.srv.addGateway(gateway); // Similarly, you may define as many Gateway objects, representing
    // various GSM modems, add them in the Service object and control all of them. // Start! (i.e. connect to all defined Gateways)
    this.srv.startService(); // Printout some general information about the modem.
    System.out.println();
    System.out.println("Modem Information:");
    System.out.println("  Manufacturer: " + gateway.getManufacturer());
    System.out.println("  Model: " + gateway.getModel());
    System.out.println("  Serial No: " + gateway.getSerialNo());
    System.out.println("  SIM IMSI: " + gateway.getImsi());
    System.out.println("  Signal Level: " + gateway.getSignalLevel() + "%");
    System.out.println("  Battery Level: " + gateway.getBatteryLevel() + "%");
    System.out.println(); // Read Messages. The reading is done via the Service object and
    // affects all Gateway objects defined. This can also be more directed to a specific
    // Gateway - look the JavaDocs for information on the Service method calls.
    msgList = new ArrayList<InboundMessage>();
    this.srv.readMessages(msgList, MessageClasses.ALL);
    for (InboundMessage msg : msgList)
    System.out.println(msg); // Sleep now. Emulate real world situation and give a chance to the notifications
    // methods to be called in the event of message or voice call reception.
    System.out.println("Now Sleeping - Hit <enter> to terminate.");
    System.in.read();
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }
    finally
    {
    this.srv.stopService();
    }
    } public class InboundNotification implements IInboundMessageNotification
    {
    public void process(String gatewayId, MessageTypes msgType, InboundMessage msg)
    {
    if (msgType == MessageTypes.INBOUND) System.out.println(">>> New Inbound message detected from Gateway: " + gatewayId);
    else if (msgType == MessageTypes.STATUSREPORT) System.out.println(">>> New Inbound Status Report message detected from Gateway: " + gatewayId);
    System.out.println(msg);
    try
    {
    // Uncomment following line if you wish to delete the message upon arrival.
    // ReadMessages.this.srv.deleteMessage(msg);
    }
    catch (Exception e)
    {
    System.out.println("Oops!!! Something gone bad...");
    e.printStackTrace();
    }
    }
    } public class CallNotification implements ICallNotification
    {
    public void process(String gatewayId, String callerId)
    {
    System.out.println(">>> New call detected from Gateway: " + gatewayId + " : " + callerId);
    }
    } public class GatewayStatusNotification implements IGatewayStatusNotification
    {
    public void process(String gatewayId, GatewayStatuses oldStatus, GatewayStatuses newStatus)
    {
    System.out.println(">>> Gateway Status change for " + gatewayId + ", OLD: " + oldStatus + " -> NEW: " + newStatus);
    }
    } public static void main(String args[])
    {
    ReadMessages app = new ReadMessages();
    try
    {
    app.doIt();
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }
    }
    }
      

  11.   


      这个问题需要注意下 jdk 的版本, 我使用的是 jdk 1.5.0.6  , 没有出现那样的问题了。
      

  12.   

    另外我把那个猫在我的机器上也实现在WEB中发短信的功能,就是不能移到其它机器上
      

  13.   

    我放在另一台也是XP的系统上,装的和我本机一样的JDK,版本是1.5.04,也是装的一样的myEclipse5.5,配的一样的环境变量,工程也导了包,一运行就报这错
    org.smslib.GatewayException: Comm library exception: java.lang.reflect.InvocationTargetException
        at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:93)
        at org.smslib.modem.AModemDriver.connect(AModemDriver.java:106)
        at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:111)
        at org.smslib.Service$1Starter.run(Service.java:227)
      

  14.   


       在你的 工程lib 下加入 commons-net-1.4.1.jar  , 你是加在 D:\Program Files\Java\jdk1.5.0_04\lib\commons-net-1.4.1.jar  ,你是加在    jdk 目录下的, 如果还是不行话参照下列条件:   To use SMSLib, you should install the following components:     SUN JDK 1.5 or newer. 
         Java Communications Library. 
         Apache ANT for building the sources. 
         Simple logging facade for Java (slf4j). 
         Apache Jakarta Commons - NET. 
      官方用法路径:http://code.google.com/p/smslib/wiki/Installation 相信楼主应该很快就可以解决, 注意几个重要 jar 包的用法, 在上面路径上已经说的很详细了, 其实只需要注意 Apache Jakarta Commons - NET.  的用法就可以了, 我没按照官方的做法来做。 呵呵.....    Good  Luck!! 
      

  15.   

    估计90%是comm.jar所对应的动态链节库win32comm.dll和properties文件没放对,
    文件javax.comm. properties拷贝到%JAVA_HOME%\jre\lib; 
    文件win32comm.dll拷贝到%JAVA_HOME%\bin。
    注意%JAVA_HOME%是jdk的路径,而非jre。
      

  16.   

    楼主是怎么做滴呀,俺也用smslib写了个通过短信猫发短信,编译过程中出现了很多的警告类如:
    2010-2-8 10:51:15 java.util.jar.Attributes read
    警告: Duplicate name in Manifest: Digest-Algorithms.
    Ensure that the manifest does not have duplicate entries, and
    that blank lines separate individual sections in both your
    manifest and in the META-INF/MANIFEST.MF entry in the jar file.
    但可以成功发送短信
    如果消除这些东西呢?
      

  17.   

    楼主是怎么做滴呀,俺也用smslib写了个通过短信猫发短信,编译过程中出现了很多的警告类如: 
    2010-2-8 10:51:15 java.util.jar.Attributes read 
    警告: Duplicate name in Manifest: Digest-Algorithms. 
    Ensure that the manifest does not have duplicate entries, and 
    that blank lines separate individual sections in both your 
    manifest and in the META-INF/MANIFEST.MF entry in the jar file. 
    但可以成功发送短信 
    如果消除这些东西呢?
    另外,在CDM命令窗口中,java -jar ***.jar运行可以运行,也出现了很多类如以上的警告,但双击则无没办法运行,郁闷,继续研究中。。
      

  18.   

    请问谁有java控制短信猫收发信息的源码给我发个好吗?
    千万分感谢我的QQ号码是317144444
      

  19.   

    确实很奇怪,前期我的短信程序也能运行。而且已经部署到相应机器上了。可这次部署出现了楼主一样的问题,郁闷!难道和JDK版本有关系?可也不对呀!有达人明白此问题的吗?给个回复!
      

  20.   

    什么是工程lib啊?是JDK中的lib,还是jre中的lib啊?
      

  21.   

    我这边显示:
    初始化成功,准备开启服务
    org.smslib.GatewayException: Comm library exception: java.lang.RuntimeException: javax.comm.NoSuchPortException
    at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:92)
    at org.smslib.modem.AModemDriver.connect(AModemDriver.java:110)
    at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:126)
    at org.smslib.Service$1Starter.run(Service.java:222)
    发送完毕!!楼主还能帮忙看看什么问题啊?
      

  22.   

    我现在也是这现一个问题,,同一台机器,,前段时间部署,,发送,接收,群发都没有问题,,现在再次启动服务出现这个bug..百思不得其解啊我都开始有点怀疑是电脑中病毒了,,杀毒又没有,,难道得重装一次系统?
      

  23.   

    不同的机器 的USB Serial Port 是不一样的,即使是同一台机器两次产生的port 也可能会不一样(COM3 、COM4),从设备管理器中看看usb端口 ,在程序中改一下就行了。