一. 将.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&