How to send SMS using SMSLib

1.9k Views Asked by At

I'm trying to send SMS using SMSLib and USB GSM modem. I'm doing this in Maven project and I have following dependencies in pom.xml:

        <dependency>
            <groupId>org.smslib</groupId>
            <artifactId>smslib</artifactId>
            <version>dev-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>org.rxtx</groupId>
            <artifactId>rxtx</artifactId>
            <version>2.1.7</version>
        </dependency>

        <dependency>
            <groupId>commons-net</groupId>
            <artifactId>commons-net</artifactId>
            <version>3.1</version>
        </dependency>

        <dependency>
            <groupId>com.googlecode.jsmpp</groupId>
            <artifactId>jsmpp</artifactId>
            <version>2.1.0</version>
        </dependency>

My java code is as follows:

Service.getInstance().start();
        Modem gateway = new Modem("ZTE", "COM5", "19200", "0000", "0000", "9800005000");        
        MsIsdn msIsdn = new MsIsdn("9841252521");
        gateway.setSmscNumber(msIsdn);
        try {
           Service.getInstance().registerGateway(gateway);
           OutboundMessage outboundMsg = new OutboundMessage(msIsdn.getAddress(), "Hello there!");
           Service.getInstance().send(outboundMsg);
        } finally {
            gateway.stop();
            Service.getInstance().stop();
        }

The documentation for SMSlib states I need to define a gateway like

XYZ g = new XYZ("my-username", "my-password");

From my understanding I believe this should be the Modem that's connected. I'm very new to this so I can't really understand what the parameters for the "Modem" constructor should like in

Modem gateway = new Modem(gatewayId, address, port, simPin, simPin2, smscNumber,memoryLocations)

OR

Modem gateway = new Modem(gatewayId, parms)

How do I know about the parameters gatewayId, address, simPin, simPin2 and memroyLocations?

Currently, I am getting following errors when running the code:

exception

java.lang.reflect.InvocationTargetException
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
......

root cause

java.lang.NoClassDefFoundError: Could not initialize class org.smslib.Service
    com.mail.utility.SendSmsUtility.sendSMS(SendSmsUtility.java:11)
    com.mail.action.SendSmsAction.sendSms(SendSmsAction.java:11)
......
0

There are 0 best solutions below