Mac中安装Thrift和使用

Thrift安装与IDEA集成

Thrift安装教程,亲测有效:https://cloud.tencent.com/developer/article/1451267
https://www.cnblogs.com/jiwawa/p/10039795.html

安装完成之后我们需要配置环境变量:
https://www.cnblogs.com/quickcodes/p/5398709.html
https://www.cnblogs.com/smartloli/p/4220545.html thrift环境变量如何配置

Thrift安装还需要安装bison,并且thrift和bison版本要对应上

安装完成之后结合idea使用教程:
https://blog.youkuaiyun.com/u010900754/article/details/80172671

注意:idea依赖的包要跟你系统安装的thrift版本一致,否则会报错

   <dependencies>
        <dependency>
            <groupId>org.apache.thrift</groupId>
            <artifactId>libthrift</artifactId>
            <version>0.9.3</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>utf-8</encoding>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.plexus</groupId>
                        <artifactId>plexus-compiler-javac</artifactId>
                        <version>1.8.1</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <attach>true</attach>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <encoding>utf-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.thrift.tools</groupId>
                <artifactId>maven-thrift-plugin</artifactId>
                <version>0.1.12-SNAPSHOT</version>
                <configuration>
                    <thriftExecutable>
                    //这个路径下的文件必须时thrift的执行文件
                        /usr/local/Cellar/thrift@0.9/0.9.3.1/bin/thrift
                    </thriftExecutable>
                   <!-- <thriftExecutable>
                        /usr/local/bin/thrift
                    </thriftExecutable>-->
                    <!-- <thriftExecutable>-->
                    <!--D:/thrift/thrift-0.9.0.exe-->
                    <!--</thriftExecutable>-->
                </configuration>
                <executions>
                    <execution>
                        <id>thrift-sources</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
macOS 系统上安装 Apache Thrift 框架可以通过多种方式进行,包括使用 Homebrew、从源码编译安装或通过其他包管理工具。以下是几种常见方法的详细说明。 ### 使用 Homebrew 安装 Thrift Homebrew 是 macOS 上最常用的包管理工具之一,可以快速安装 Thrift 及其依赖项。 1. 确保系统中已安装 [Homebrew](https://brew.sh/),如果尚未安装,可通过以下命令安装: ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` 2. 使用 Homebrew 安装 Thrift: ```bash brew install thrift ``` 3. 安装完成后,验证安装是否成功: ```bash thrift -version ``` 该方法适用于大多数用户,能够快速完成安装且无需手动配置依赖项。 ### 从源码编译安装 Thrift 如果需要特定版本的 Thrift 或者希望自定义编译选项,则可以从源码进行安装。 1. 安装必要的依赖项(如 automake、libtool、pkg-config 等): ```bash brew install automake libtool pkg-config ``` 2. 下载 Thrift 源码包(以 0.17.0 版本为例): ```bash git clone https://github.com/apache/thrift.git cd thrift git checkout v0.17.0 ``` 3. 配置并编译 Thrift: ```bash ./bootstrap.sh ./configure --without-qt4 --without-cpprest --without-openssl make sudo make install ``` 4. 验证安装: ```bash thrift -version ``` 该方法适合需要定制化安装或参与 Thrift 开发的用户。 ### 使用 Python pip 安装 Thrift 库(仅限 Python) 如果仅需使用 Thrift 的 Python 库,可通过 pip 安装: ```bash pip install thrift ``` 该方式不会安装 Thrift 编译器(thrift compiler),仅适用于已经拥有 `.thrift` 接口定义文件并需要生成 Python 代码的场景。 ### Thrift 自动化运维体系集成 安装完成后,结合引用中提到的 Thrift 自动化运维体系,可将 Thrift 服务集成到服务注册中心、监控系统、日志系统等组件中,实现服务的自动注册、健康检查、动态配置更新等功能[^3]。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值