How to send SMS using Twilio API in Java?

I came across a question on yesterday. As, I have used Twilio API to send SMS and do Phone Call many times. I signed up to help the OP.

If you wanna compile following code in your local box, then you need to have JSON.jar and commons-codec-1.8.jar JAR files. Download File Archive

I wrote this class to generalize any Web Related Helper Methods.

To output property, I used Bootstrap 2.3.2 in following JSP.

If you get all things working, the output would look like this.


7 thoughts on “How to send SMS using Twilio API in Java?

  1. Where to get the json.jar
    I get the following error

    Exception in thread “main” java.lang.NoClassDefFoundError: org/codehaus/jackson/JsonParseException
    at com.twilio.sdk.TwilioRestResponse.getParser(
    at com.twilio.sdk.TwilioRestResponse.toMap(
    at com.twilio.sdk.resource.list.SmsList.create(
    at Example.main(
    Caused by: java.lang.ClassNotFoundException: org.codehaus.jackson.JsonParseException
    at Method)
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    … 4 more

  2. Well, I guess! You are using some other package! com.twilio.sdk.* I did not use any SDK to call API in my example.

    If you see stacktrace, you are getting error Class not found exception for org.codehaus.jackson.JsonParseException!

    You should get latest Jackson JSON Parser from

  3. This is very good!
    How to send bulk SMS from this API, I have to send SMS for all new customers who are registering into my application so I have stored their contact numbers in the database and from there I need to fire bulk SMS on various occasions to all of them like if there is a new offer or something like that through my Java code. Is that possible with this API? I do not need UI that makes the user type their own message and it should be automated for 1000s of users. I have done the e-mail part but stuck with the SMS.

  4. Hello Praveen,

    You should read following link to send Bulk SMS via Twilio API.


  5. how to send sms in my website using bulk sms

  6. Thanks. The post is still relevant to beginners like me.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.