Results 1 to 6 of 6
  1. #1
    j_arif123 is offline Member
    Join Date
    Jan 2012
    Location
    India
    Posts
    34
    Rep Power
    0

    Default Sending SMS using smslib

    for my project , i need to send and receive sms from my java application. After many attempt , now i am trying to achieve it by using smslib a java library . you can get it from SMSLib where they did not give explanation about how to use it . So , i went to a blog [Moderator edit: link removed] . I followed the instruction provided in the blog . It was successful in compiling the code given below . When i run it , very common error was thrown . But i dont know to clear it . Ther error message is :
    D:\downloads\java sms library\smslib\src\java\examples\modem>java MyMessage
    Exception in thread "main" java.lang.NoClassDefFoundError: org/smslib/IOutboundM
    essageNotification
    at MyMessage.main(MyMessage.java:76)
    Caused by: java.lang.ClassNotFoundException: org.smslib.IOutboundMessageNotifica
    tion
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 1 more
    Java Code:
    // MyMessage.java - Sample application.
    //
    // This application shows you the basic procedure for sending messages.
    // You will find how to send synchronous and asynchronous messages.
    //
    // For asynchronous dispatch, the example application sets a callback
    // notification, to see what's happened with messages.
    
    
    import org.smslib.AGateway;
    import org.smslib.IOutboundMessageNotification;
    import org.smslib.Library;
    import org.smslib.OutboundMessage;
    import org.smslib.Service;
    import org.smslib.modem.SerialModemGateway;
    import org.smslib.*;
    
    class SendMessage
    {
    	public void doIt() throws Exception
    	{
    		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());
    		SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM4", 460800, "Nokia", "300");
    		gateway.setInbound(true);
    		gateway.setOutbound(true);
    		gateway.setSimPin("0000");
    		// Explicit SMSC address set is required for some modems.
    		// Below is for VODAFONE GREECE - be sure to set your own!--- i set my own
    		gateway.setSmscNumber("+91989444451914");
    		Service.getInstance().setOutboundMessageNotification(outboundNotification);
    		Service.getInstance().addGateway(gateway);
    		Service.getInstance().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() + " dBm");
    		System.out.println("  Battery Level: " + gateway.getBatteryLevel() + "%");
    		System.out.println();
    		// Send a message synchronously.
    		OutboundMessage msg = new OutboundMessage("+918344333400", "Hello from SMSLib!");
    		Service.getInstance().sendMessage(msg);
    		System.out.println(msg);
    		// Or, send out a WAP SI message.
    		//OutboundWapSIMessage wapMsg = new OutboundWapSIMessage("306974000000",  new URL("http://www.smslib.org/"), "Visit SMSLib now!");
    		//Service.getInstance().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!");
    		//srv.queueMessage(msg, gateway.getGatewayId());
    		//msg = new OutboundMessage("308888888888", "Wrong number!");
    		//srv.queueMessage(msg, gateway.getGatewayId());
    		System.out.println("Now Sleeping - Hit <enter> to terminate.");
    		System.in.read();
    		Service.getInstance().stopService();
    	}
    
    	public class OutboundNotification implements IOutboundMessageNotification
    	{
    		public void process(AGateway gateway, OutboundMessage msg)
    		{
    			System.out.println("Outbound handler called from Gateway: " + gateway.getGatewayId());
    			System.out.println(msg);
    		}
    	}
    }
    class MyMessage {
    	public static void main(String args[]) throws Exception
    	{
    		SendMessage app = new SendMessage();
    		try
    		{
    			app.doIt();
    		}
    		catch (Exception e)
    		{
    			e.printStackTrace();
    		}
    	}
    }
    Thanks a lot....in advance.... :-)
    Last edited by DarrylBurke; 07-01-2013 at 11:59 AM. Reason: Removed spammy link

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default Re: Sending SMS using smslib

    The jar file containing that class (presumably the SMSLib jar) is not on your runtime classpath.
    Since you do not supply a classpath to the 'java' command then I can only assume that the jar file is not in the <...>/java/examples/modem directory.
    EIther put the jar file in there, or add a '-cp .;<path to the jar file>' to the command.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    j_arif123 is offline Member
    Join Date
    Jan 2012
    Location
    India
    Posts
    34
    Rep Power
    0

    Default Re: Sending SMS using smslib

    Thanks a lot.... Tols.. I got some partial output .... still there is some proble.... there is a list of jar files which were copied in different locations according to the blog i mentioned in the post above... I got following output ....

    D:\downloads\java sms library\smslib\src\java\examples\modem>java -cp smslib3.ja
    r; MyMessage
    Example: Send message from a serial gsm modem.
    SMSLib: A Java API library for sending and receiving SMS via a GSM modem or othe
    r supported gateways.
    This software is distributed under the terms of the Apache v2.0 License.
    Web Site: SMSLib
    Version: 3.5.2
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Prio
    rity
    at org.smslib.Service.listSystemInformation(Service.j ava:113)
    at org.smslib.Service.initializeService(Service.java: 103)
    at org.smslib.Service.<init>(Service.java:95)
    at org.smslib.Service.<clinit>(Service.java:90)
    at SendMessage.doIt(MyMessage.java:33)
    at MyMessage.main(MyMessage.java:79)
    Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Priority
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 6 more


    Did you visit the blog which i mentioned above? ( i think you may track the problem if you have a look at [Moderator edit: link removed])

    please note that i dont have much experiance in working with jar files .
    Last edited by DarrylBurke; 07-01-2013 at 11:58 AM. Reason: Removed spammy link

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default Re: Sending SMS using smslib

    I don't really need to visit the blog.
    You need to collect together all the jar files your code (and SMSLib) depends on and stick them in one place, probably in a lib directory next to your app.
    Then you can simply use 'java -cp .;lib/*.jar MyMessage' and all these ClassNotFound problems go away.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    j_arif123 is offline Member
    Join Date
    Jan 2012
    Location
    India
    Posts
    34
    Rep Power
    0

    Default Re: Sending SMS using smslib

    Still i could not clear it .... i tried it in netbeans...... it said after building :

    Example: Send message from a serial gsm modem.
    SMSLib: A Java API library for sending and receiving SMS via a GSM modem or other supported gateways.
    This software is distributed under the terms of the Apache v2.0 License.
    Web Site: SMSLib
    Version: 3.5.2
    SLF4J: Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError.
    SLF4J: See also SLF4J Error Codes for more details.
    Exception in thread "main" java.lang.ExceptionInInitializerError
    at org.apache.log4j.Logger.getLogger(Logger.java:39)
    at org.smslib.helper.Logger.<init>(Logger.java:49)
    at org.smslib.helper.Logger.<clinit>(Logger.java:29)
    at org.smslib.Service.listSystemInformation(Service.j ava:113)
    at org.smslib.Service.initializeService(Service.java: 103)
    at org.smslib.Service.<init>(Service.java:95)
    at org.smslib.Service.<clinit>(Service.java:90)
    at SendMessage.doIt(SendSMSLib.java:34)
    at SendSMSLib.main(SendSMSLib.java:83)
    Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError. See also SLF4J Error Codes for more details.
    at org.apache.log4j.Log4jLoggerFactory.<clinit>(Log4j LoggerFactory.java:49)
    ... 9 more
    Java Result: 1
    BUILD SUCCESSFUL (total time: 1 second)

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default Re: Sending SMS using smslib

    Read the message:
    Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError. See also

    It's telling you exactly what the problem is.
    log4j only needs one of those jars, and fails if it finds both, so remove one of them from your project.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Sending fax
    By mantas.brasiunas in forum New To Java
    Replies: 8
    Last Post: 07-04-2012, 04:43 AM
  2. sending sms from jsp
    By krishnareddy in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 01-31-2012, 11:19 AM
  3. Replies: 0
    Last Post: 11-07-2011, 09:48 AM
  4. Sending XML
    By zzpprk in forum XML
    Replies: 17
    Last Post: 03-02-2011, 01:00 PM
  5. configure smslib in Eclipse
    By javanese in forum Eclipse
    Replies: 1
    Last Post: 03-01-2009, 04:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •