新建一個maven項目,先下載maven依賴 http://thrift.apache.org/download
<dependency> <groupId>org.apache.thrift</groupId> <artifactId>libthrift</artifactId> <version>0.11.0</version> </dependency>
再安裝需要的工具 http://thrift.apache.org/docs/install/os_x
我的是MacBook Pro,按照要求,
安裝thrift的工具依賴boost庫
下載地址:www.boost.org,找到最新的版本下載,
下載之后解壓,然后用cmd模式進入到解壓文件夾的根目錄。
執行命令
./bootstrap.sh sudo ./b2 threading=multi address-model=64 variant=release stage install
如果出現missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun錯誤,
先執行
xcode-select --install
安裝thrift的工具依賴libevent庫
下載地址:http://libevent.org,找一個穩定版本下載,
下載之后解壓,然后用cmd模式進入到解壓文件夾的根目錄。
執行命令:
./configure --prefix=/usr/local make sudo make install
make的時候出現 fatal error: 'openssl/bio.h' file not found
這是由於mac默認安裝了openssl但是沒有安裝對應的include頭文件和lib庫,故這里使用homebrew(參考https://brew.sh/index_zh-cn.html)來安裝最新的openssl
先安裝homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
再用homebrew安裝openssl(xcode要是最新版本的才能安裝):
brew install openssl brew link openssl --froce ln -s /usr/local/opt/openssl/bin/openssl /usr/local/bin/openssl ln -s /usr/local/opt/openssl/include/openssl /usr/local/include/openssl ln -s /usr/local/opt/openssl/lib/libssl.a /usr/local/lib/libssl.a ln -s /usr/local/opt/openssl/lib/libcrypto.a /usr/local/lib/libcrypto.a
然后重新運行 make 和 sudo make install 命令來安裝libevent
安裝Apache Thrift
下載最新版本的thrift 0.11,下載地址:http://archive.apache.org/dist/thrift/
解壓下載的文件,進入該目錄,運行以下腳本
./configure --prefix=/usr/local/ --with-boost=/usr/local --with-libevent=/usr/local
make sudo make install
如果報錯error: Bison version 2.5 or higher must be installed on the system!
運行thrift -version 命令查看thrift版本即可