Friday, January 6, 2012

First Steps of Apache Thrift with Java in Linux


Apache Thrift is a software framework for scalable cross-language services development. It was originally developed by Facebook before it was donated to Apache Software Foundation.  

Download the stable release

Unpack the tar.gz archive to a directory you prefer
(say home /home/amila/apacheThrift)


You need JDK and Apache Ant at least to run Thrift's Java tutorial.
(You can refer to my previous posts to find how to install JDK on ubuntu.)

Use apt-get to install Ant

 

We first need to install Thrift compiler and language variables before we start developing we Thrift.

There are several required packages to install Thrift that are not installed on a linux distribution by default.
To install those
 


Goto top level directory of unpacked thrift distribution
(eg: /home/amila/apacheThrift/thrift-0.8.0)
 
 

During this process, thrift will scan and list the different language found.
It should say:

..along with other languages found on your computer.

However, to configure Thrift for all those languages, you may need to install additional packages

Now you can make Thrift:
 

You might get some error if all required libraries for the languages configured in above step are not present.

In that case, you can deselect the packages you don't need when configuring
For example, say you don't need the support for Ruby. When configuring, you can use:
 
(I had to deselect erlang libraries to get it working on ubuntu 11.04)

After make is completed successfully, install Thrift by,

 

To check if the installation is successfully completed:
 

You should get an output like:
 

Tutorial are located at ./tutorials directory.

There you will find two files tutorials.thrift and shared.thrift

.thrift files describe the interfaces (IDL) in terms of the classes, methods they include.


 

This will create a directory named "gen-java" inside your current directory which will include generated Java classes according to specified thrift file.

Now goto the directory "java" inside the current directory (tutorial) and execute ant.
The ant script will compile both generated source files and the source file inside java directory and build a jar file.

Finally, run the tutorial by:
 

You may also find this page useful.

1 comment:

Ing. Ricardo Jorge Hera said...

Hola, está muy bueno el blog con todos los consejos pero tengo un problema para instalar la herramienta, lo que pasa es que mientras instala pide un fichero de internet que no lo puede descargar, el problema es que mi conexión a internet no es directa, sino mediante un proxy por el que hay que autenticarse y no se llega a descargar el fichero, al final el proceso de instalación me da error y no se como solucionarlo. Me podrias ayudar?? Mi correo es rhera@hab.uci.cu

Saludos