grpc 入门问题

本文介绍了如何使用 protoc 编译 .proto 文件为 Java 代码,详细步骤包括下载 protoc 工具,解决.proto 文件路径问题,以及生成 Grpc.java 文件。同时提供了 pom.xml 的依赖添加方法,以及客户端和服务端的创建指南。
摘要由CSDN通过智能技术生成

一. 将.proto 文件编译出java文件

1.下载对应系统的protoc;

【自用链接:https://pan.baidu.com/s/1yTwRi8CzvnjX9ICRExQpqQ 密码:mrow】

2.在proto.exe所在文件目录下打开命令行(shift+右键),执行:   

   protoc -I=E:\tmp --java_out=./ E:\tmp\send_mail.proto

【protoc.exe -I=.\读取目录 --java_out=./ 读取目录\send_mail.proto;】

 

a.加上 -I 是因为.proto文件不在当前目录下,出现问题:

File does not reside within any path specified using --proto_path (or -I).  You must specify a --proto_path which encompasses this file.  Note that the proto_path must be an exact prefix of the .proto file names -- protoc is too dumb to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think).;

 

b.用--java_out 是因为用 -java_out ,出现问题:

-j 命令不存在;

 

3.继续,执行: protoc.exe --plugin=protoc-gen-grpc-java=./protoc-gen-grpc-java-1.0.1-windows-x86_64.exe --grpc-java_out=./ send_mail.proto 生成Grpc.java文件;

4.将生成java文件复制到项目中;

 

二.附件

1.pom.xml

>添加依赖


      <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
      </dependency>


      <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
          <version>1.7.14</version>
      </dependency>


      <!-- 添加Servlet -->
      <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>javax.servlet-api</artifactId>
          <version>3.1.0</version>
          <scope>provided</scope>
      </dependency>
      <!-- 添加grpc依赖 -->
      <dependency>
        <groupId>io.grpc</groupId>
        <artifactId>grpc-all</artifactId>
        <version>1.1.2</version>
      </dependency>
      <!--    cassandra 相关 -->
      <!--     thrift 连接方式 -->
      <dependency>
          <groupId>org.apache.cassandra</groupId>
          <artifactId>cassandra-thrift</artifactId>
          <version>2.1.17</version>
      </dependency&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值