Java web applications can easily dial and receive phone calls by combining the Spark web framework with the Twilio Voice API. Our example phone calls will say a snippet of text then play an MP3 file, but they can easily be modified to provide other useful actions like gathering user input from the number pad or creating conference calls.

Our Project Tools

Our Spark web app will use the Java 8 JDK and Apache Maven so make sure you have those tools installed. If you need to get Java 8 and Apache Maven installed on your Windows machine, check out this tutorial (you can skip over the GWT bits). We will also need the following tools throughout this walkthrough:

You can snag all the code for this tutorial in the java-twilio-example-apps GitHub repository. Copy and modify the code as you see fit – it is all open source under the MIT license.

Starting Our Project

IntelliJ can create our project boilerplate for us as well as install Spark and the Twilio Java helper library.

Start IntelliJ and select “Create New Project”, then choose Maven.



Click Next, then fill in the GroupId , ArtifactId and Version on the New Project screen. You can keep the defaults shown in the following screenshot or use your own settings.



Click the “Next” button. On the following screen, fill in javaCalls for the Project name and place the project in its own subdirectory under where you keep your Java projects.



I typically store my projects under the C:\devel\projects path, but you can put this folder wherever your projects are typically located.

Click the “Finish” button and IntelliJ will open up the IDE.



Now we’re ready to install the project dependencies via Maven and finally get to coding.

Installing Our Dependencies