java 短信猫开发,smslib库文件配置问题
在用MyEclipse作短线猫开发时,买了一个叫“USR-GPRS-MODEM”的短信猫,在百般测试查资料情况下终于联通了无线猫(在淘宝上买的,一个叫有人科技的公司,售后很不给力)。然后按照步骤做配置,网上有很多,大致都是:
短信猫java配置方法:
1).slf4j-api-1.5.2.jarslf4j-api-1.5.2-sources.jarslf4j-nop-1.5.2.jarcomm.jarsmsserver-3.4.1.jarsmslib-3.4.1.jar将上述6个jar包拷贝到lib下2).在Windows环境下使用SMSLib编程的时候,我们需要做一下comm的配置:1. 将win32com.dll放置在%JAVA_HOME%/jre/bin下2. 将comm.jar放置在%JAVA_HOME%/jre/lib/ext下3. 将javax.comm.properties放置在%JAVA_HOME%/jar/lib下3).测试代码package examples.modem; import org.smslib.IOutboundMessageNotification; import org.smslib.Library; import org.smslib.OutboundMessage; import org.smslib.Service; import org.smslib.modem.SerialModemGateway; public class SendMessage { public void doIt() throws Exception { Service srv; OutboundMessage msg; OutboundNotification outboundNotification = new OutboundNotification(); System.out.println("Example: Send message from a serial gsm modem."); System.out.println(Library.getLibraryDescription()); System.out.println("Version: " + Library.getLibraryVersion()); srv = new Service(); SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM3", 57600, "Nokia", "6310i"); gateway.setInbound(true); gateway.setOutbound(true); gateway.setSimPin("0000"); srv.setOutboundNotification(outboundNotification); srv.addGateway(gateway); srv.startService(); 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(); // Send a message synchronously. msg = new OutboundMessage("+306948494037", "Hello from SMSLib!"); srv.sendMessage(msg); System.out.println(msg); // Or, send out a WAP SI message. //OutboundWapSIMessage wapMsg = new OutboundWapSIMessage("+223123124", new URL("https://mail.google.com/"), "Visit GMail now!"); //srv.sendMessage(wapMsg); //System.out.println(wapMsg); // You can also queue some asynchronous messages to see how the callbacks // are called... //msg = new OutboundMessage("+309999999999", "Wrong number!"); //msg.setPriority(OutboundMessage.Priorities.LOW); //srv.queueMessage(msg, gateway.getGatewayId()); //msg = new OutboundMessage("+308888888888", "Wrong number!"); //msg.setPriority(OutboundMessage.Priorities.HIGH); //srv.queueMessage(msg, gateway.getGatewayId()); 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(); } } }
但是怎么测试都出现如下错误:
查了很多资料,大致意思是说,配置的文件没有配置对。找了5小时没找到解决办法。无奈躺下休息一会,思来想去,是不是我不能用MyEclipse操作串口呢,不管是短信猫还是别的设备,我就查了相关资料,果然发现了问题。MyEclipse的部分库在自己的软件目录下,程序运行时,就会在自己的目录下查找这些库,而我们导入的一些配置文件都在jdk目录下,MyEclipse根本访问不到,悲催吧。解决办法有两种:一.在MyEclipse中配置库文件路径,设置为jdk的目录:Preferences->Java->Installed JREs,点击add,加入jdk目录
二.和上面的jdk中配置smslib库的方法相似,将那些文件放到MyEclipse的默认jdk的相关文件夹下。如路径:MyEclipse\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013你是否也遇到这种问题呢,可以按上述方法试试!