Search code examples
javathrift

How can I compile an Apache Thrift definition file?


I'm trying to compile an Apache Thrift definition file (on Ubuntu). I keep getting the error message: Could not open input file with realpath: Calculator.thrift whenever I enter thrift -r --gen java Calculator.thrift into the command line. I have already installed Thrift. Where should I save .thrift definition files so that it will be possible to compile them?


Solution

  • In the tutorial directory that comes with the thrift installation, you should see the following 2 *.thrift files:

    shared.thrift
    tutorial.thrift
    

    From this same directory you should be able to generate/compile from the thrift IDL files as follows:

    thrift -r --gen java ./tutorial.thrift
    

    This should create a gen-java sub-directory in the tutorial directory.

    The Calculator.thrift file does not actually exist, the Calculator service is defined in tutorial.thrift. The error is trying to tell you that it cant find the file, and rightly so, since it doesnt actually exist :)