The Twilio Java Helper Library

Deprecation notice: New functionality will only be added to the new libraries (Java 7.x). The old libraries (Java 6.x) will be officially supported until 01/15/16. After that day, Twilio will stop providing bug fixes and Support might ask you to upgrade before debugging issues.

The Twilio Java SDK makes it easy to interact with the Twilio API from your Java application. The most recent version of the Twilio Java SDK can be found on Maven Repository. The Twilio SDK requires Java SE 7 or higher. If you are interested in migrating to the newer 7.x version of the Twilio Java SDK from the 6.x version, check out this guide.

Using with Maven

The recommended method for installing the SDK is with Maven. You can add the following dependency to your existing project, specifying the latest version in the version tag. Place the following within your <dependencies> tag in your pom.xml file:

<dependency>
  <groupId>com.twilio.sdk</groupId>
  <artifactId>twilio</artifactId>
  <version>(7.0,7.9)</version>
</dependency>

Or, you can clone the source code for the SDK, and install the library from there.

git clone https://github.com/twilio/twilio-java
cd twilio-java
mvn install       # Requires maven, download from http://maven.apache.org/download.html

You may need to run the above command with sudo (e.g. sudo mvn install) if you get "Permission Denied" errors while trying to install the library.

Using without Maven

While we recommend using a package manager to track the dependencies in your application, it is possible to download and use the Java SDK manually by downloading a pre-built jar file. Select the directory for the latest version and download one of these jar files:

  • twilio-7.x.x-with-dependencies.jar
  • twilio-7.x.x.jar -- use this if you have issues with conflicting jars in your project. You'll need to include versions of the dependencies yourself. See the pom.xml file in the source code for the list of libraries.

Testing your Installation

Try sending yourself an SMS message, like this:

import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    Message message = Message.creator(new PhoneNumber("+15558675309"),
        new PhoneNumber("+15017250604"), 
        "This is the ship that made the Kessel Run in fourteen parsecs?").create();

    System.out.println(message.getSid());
  }
}

More Documentation

Once you're up and running with the Java SDK, you'll find code samples using the latest version in our REST API docs and in the documentation for every Twilio product. You can also find auto-generated Javadoc for the latest Java SDK here.

Accessing the 6.x Version of the SDK

The most recent version of the Java SDK is not API compatible with the previous 6.x version of the Java SDK you may have used in previous Twilio applications. The older version will continue to work, and you will continue to find sample code for this version throughout our documentation. Should you need to install this version with Maven, you can do so with the following dependency in your pom.xml file:

<dependency>
  <groupId>com.twilio.sdk</groupId>
  <artifactId>twilio-java-sdk</artifactId>
  <version>6.3.0</version>
</dependency>

Alternately, you can find a pre-built jar and download it directly from there. Select the directory for the latest version and download one of these jar files:

  • twilio-6.x.x-with-dependencies.jar
  • twilio-6.x.x.jar -- use this if you have issues with conflicting jars in your project. You'll need to include versions of the dependencies yourself. See the pom.xml file in the source code for the list of libraries.

Accessing Preview Twilio Features

Pre-release products are only available in the "alpha" release of the Java SDK (version 7.x or higher). You can read more about the versioning strategy for the SDK here. Whenever a new version of the SDK is released, a corresponding "alpha" version will also be released and installable. For example, if the current production version of the SDK were "7.0.2", you could install the "alpha" version with the following dependency in your pom.xml file:

<dependency>
  <groupId>com.twilio.sdk</groupId>
  <artifactId>twilio</artifactId>
  <version>7.0.2-alpha1</version>
</dependency>

Getting Help

We'd love to hear your feedback on the Java SDK, and help you past any issues you may encounter. Feel free to drop us a line, and we'll make sure to get you sorted!