protoc的protoc-gen-grpc-java插件
编译 protoc-gen-grpc-java插件 的文档在:
https://github.com/grpc/grpc-java/tree/master/compiler
编译的步骤:
Change to the compiler directory:
$ cd $GRPC_JAVA_ROOT/compiler
To compile the plugin:
$ ../gradlew java_pluginExecutable
To test the plugin with the compiler:
$ ../gradlew java_pluginExecutable
编译过程中如果出现下面错误: fatal error: 'google/protobuf/io/zero_copy_stream.h' file not found。
是因为找不到这些头文件。找不到的原因如下:
Some versions of Mac OS X (e.g., 10.10) doesn't have /usr/local in the default search paths for header files and libraries.
It will fail the build of the codegen. To work around this, you will need to set environment variables:
$ export CXXFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"
参考: https://github.com/grpc/grpc-java/blob/master/COMPILING.md
错误的时候提示信息:
$ ../gradlew java_pluginExecutable
Download https://repo1.maven.org/maven2/org/mortbay/jetty/alpn/jetty-alpn-agent/2.0.2/jetty-alpn-agent-2.0.2.pom
Download https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-parent/25/jetty-parent-25.pom
*** Building codegen requires Protobuf version 3.0.0-beta-2
*** Please refer to https://github.com/grpc/grpc-java/blob/master/COMPILING.md#how-to-build-code-generation-plugin
:grpc-compiler:compileJava_pluginExecutableJava_pluginCpp
/Users/ghj1976/project/github/grpc/grpc-java/compiler/src/java_plugin/cpp/java_generator.h:8:10: fatal error: 'google/protobuf/io/zero_copy_stream.h' file not found
#include <google/protobuf/io/zero_copy_stream.h>
^
1 error generated.
In file included from /Users/ghj1976/project/github/grpc/grpc-java/compiler/src/java_plugin/cpp/java_plugin.cpp:8:
/Users/ghj1976/project/github/grpc/grpc-java/compiler/src/java_plugin/cpp/java_generator.h:8:10: fatal error: 'google/protobuf/io/zero_copy_stream.h' file not found
#include <google/protobuf/io/zero_copy_stream.h>
^
1 error generated.
In file included from /Users/ghj1976/project/github/grpc/grpc-java/compiler/src/java_plugin/cpp/java_generator.cpp:1:
/Users/ghj1976/project/github/grpc/grpc-java/compiler/src/java_plugin/cpp/java_generator.h:8:10: fatal error: 'google/protobuf/io/zero_copy_stream.h' file not found
#include <google/protobuf/io/zero_copy_stream.h>
^
1 error generated.
:grpc-compiler:compileJava_pluginExecutableJava_pluginCpp FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':grpc-compiler:compileJava_pluginExecutableJava_pluginCpp'.
> Multiple build operations failed.
C++ compiler failed while compiling java_generator.h.
C++ compiler failed while compiling java_plugin.cpp.
C++ compiler failed while compiling java_generator.cpp.
See the complete log at: file:///Users/ghj1976/project/github/grpc/grpc-java/compiler/build/tmp/compileJava_pluginExecutableJava_pluginCpp/output.txt
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1 mins 24.831 secs
正确的时候的提示信息:
$ ../gradlew java_pluginExecutable
*** Building codegen requires Protobuf version 3.0.0-beta-2
*** Please refer to https://github.com/grpc/grpc-java/blob/master/COMPILING.md#how-to-build-code-generation-plugin
:grpc-compiler:compileJava_pluginExecutableJava_pluginCpp
:grpc-compiler:linkJava_pluginExecutable
:grpc-compiler:java_pluginExecutable
BUILD SUCCESSFUL
Total time: 14.818 secs
This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.11/userguide/gradle_daemon.html
localhost:compiler ghj1976$
$ ../gradlew java_pluginExecutable
Downloading https://services.gradle.org/distributions/gradle-2.13-bin.zip
.....................................................................................................................................................................................
Unzipping /Users/ghj1976/.gradle/wrapper/dists/gradle-2.13-bin/4xsgxlfjcxvrea7akf941nvc7/gradle-2.13-bin.zip to /Users/ghj1976/.gradle/wrapper/dists/gradle-2.13-bin/4xsgxlfjcxvrea7akf941nvc7
Set executable permissions for: /Users/ghj1976/.gradle/wrapper/dists/gradle-2.13-bin/4xsgxlfjcxvrea7akf941nvc7/gradle-2.13/bin/gradle
*** Building codegen requires Protobuf version 3.0.0-beta-2
*** Please refer to https://github.com/grpc/grpc-java/blob/master/COMPILING.md#how-to-build-code-generation-plugin
:grpc-compiler:compileJava_pluginExecutableJava_pluginCpp
:grpc-compiler:linkJava_pluginExecutable
:grpc-compiler:java_pluginExecutable
BUILD SUCCESSFUL
Total time: 4 mins 29.65 secs
This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.13/userguide/gradle_daemon.html
localhost:compiler ghj1976$
我这里编译后的文件在下面目录的 protoc-gen-grpc-java 文件:
/Users/ghj1976/project/github/grpc/grpc-java/compiler/build/exe/java_plugin
对于需要产生Java版本的gRPC自动编译代码的,需要做下面几步:
1、下载 protoc,对于原来就在用 protoc 的人来说,需要注意替换成 3.0 的版本。下载、使用方法参考: http://www.cnblogs.com/ghj1976/p/5435565.html
2、同时去官网下载protoc-gen-grpc-java的源码自行在本地编译(参考本文上面部分)。
3、然后使用 protoc 命令时指定 --plugin编译,不要试图使用 IDE 的protobuf 插件。
http://evthoriz.com/2015/07/07/gRPC-tutorial/
具体产生 java 版gRPC代码的命令如下:
$ protoc --plugin=protoc-gen-grpc-java=build/binaries/java_pluginExecutable/protoc-gen-grpc-java \
--grpc-java_out="$OUTPUT_FILE" --proto_path="$DIR_OF_PROTO_FILE" "$PROTO_FILE"
具体到我这里的代码就是:
$ protoc --plugin=protoc-gen-grpc-java=/Users/ghj1976/project/github/grpc/grpc-java/compiler/build/exe/java_plugin/protoc-gen-grpc-java --grpc-java_out=./java/ ./proto/helloworld.proto
产生 android 使用的 java-nano 代码方法如下:
$ protoc --plugin=protoc-gen-grpc-java=build/binaries/java_pluginExecutable/protoc-gen-grpc-java \
--grpc-java_out=nano:"$OUTPUT_FILE" --proto_path="$DIR_OF_PROTO_FILE" "$PROTO_FILE"
具体到我这里的代码就是:
$ protoc --plugin=protoc-gen-grpc-java=/Users/ghj1976/project/github/grpc/grpc-java/compiler/build/exe/java_plugin/protoc-gen-grpc-java --grpc-java_out=nano:./javanano/ ./proto/helloworld.proto
参考:
protoc not generating service stub files
http://stackoverflow.com/questions/31029675/protoc-not-generating-service-stub-files
protoc的protoc-gen-grpc-java插件的更多相关文章
- 解决Ubuntu下Firefox+OpenJDK没有Java插件的问题
如果是安装的OpenJDK,很遗憾它是没有libnpjp2.so的. 此时按照网上各种奇怪的方法都挣扎无效,但可以用icedtea插件来解决这个问题. icedtea的版本与本机安装的OpenJDK版 ...
- 关于Chrome浏览器不能使用Java插件的问题
最近测试的“上海电信宽带测速系统”中HTTP测试需要用到java插件,之前装过好多次插件,装好后还是提示java插件未安装,郁闷了N久,最近问题终于得到了解决,故做分享~ 关于Chrome浏览器不能使 ...
- 几款常用Eclipse java插件
以下是我最近常用的几款Eclipse java插件: ADT Plugin https://dl-ssl.google.com/android/eclipse/ WindowBuilder Pro ...
- Linux下启用Chrome/Firefox的Java插件
JDK 已经安装好,可是浏览器执行 Java Applet 时提示需安装 Java 插件. 这时,在浏览器安装文件夹中 plugins 文件夹下创建2个重要的符号链接就可以. libnpjp2.so ...
- Gradle 1.12用户指南翻译——第二十三章. Java 插件
其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Github上的地址: https://g ...
- 【解决Jira】Chrome提示Java插件因过期而遭到阻止(JIRA上传截屏截图)
最近经常被这个问题所困扰:用Chrome访问JIRA上传截屏截图时,地址栏下面弹出通知,提示JAVA插件已过期.但是由于公司要求统一开发环境和设置,不能更新到最新版,就像这样: 结果网页上的Java就 ...
- Gradle Java 插件
Java 插件是构建 JVM 项目的基础,它为项目增加了很多能力,例如编译,测试,打包,发布等等. 很多插件都是基于 Java 插件实现的,例如 Android 插件. 用法 使用 id 应用插件 p ...
- VS Code Java 更新 – 全新Gradle for Java插件,更方便的代码操作, 1.0 语言支持发布
大家好,欢迎来到 9 月版的 Visual Studio Code Java 更新.在这篇文章中,我们将分享我们最新的Gradle插件,更加方便的代码操作(Getter/Setter等等),以及最近的 ...
- VS Code Java 3月更新|代码补全、Maven 以及 Java 插件预览版本新升级!
Nick Zhu Senior Program Manager, Developer Division at Microsoft 大家好,欢迎来到 Visual Studio Code Java 的 ...
- gRPC Java的代码架构
RPC(远程过程调用) 的架构最常见的是"动态代理"方式,事先定义好接口,用一个代理假装实现了这个接口(真正的实现放在服务端),供客户端调用,代理内部将该方法调用封装成一个网络请求 ...
随机推荐
- curl命令使用大全
curl命令使用大全 可以看作命令行浏览器 1.开启gzip请求curl -I http://www.sina.com.cn/ -H Accept-Encoding:gzip,defalte 2.监控 ...
- Intent的详细解析以及用法
Intent的详细解析以及用法 Android的四大组件分别为Activity .Service.BroadcastReceiver(广播接收器).ContentProvider(内容提供者 ...
- DBA常用SQL之DDL生成语句
获取对象定义的包为:dbms_metadata,其中的get_ddl函数是获取对象的函数 GET_DDL函数返回创建对象的原数据的DDL语句,参数说明 .object_type ---需要返回原数据的 ...
- Oracle视图详解
转载自:http://blog.itpub.net/29785807/viewspace-1270120/ 一. 视图的定义 视图(view),也称虚表, 不占用物理空间,这个也是相对概念,因为视图本 ...
- CGI相关概念
common gateway interface 通用网关接口 可以让客户端从浏览器向执行在服务器上的程序请求数据.CGI描述了客户端和服务器程序之间传输数据的一种标准. 编程语言perl是一种被广泛 ...
- C/C++ 函数压栈方式
一,不同关键字,系统压栈方式 1,如果函数func是__cdecl(VC下的默认调用方式),调用时情况如下 int main() { //参数从右到左压栈 push 4 pus ...
- 剑指offer系列52---约瑟夫环问题
[题目]0,1,...n排成一个圈,从0开始每次删除第m个数,求圆圈最后个数. * [思路]1 用数组模拟圆圈.当数到最后一个数即index==n时,令index==0 重头开始遍历: * 当遇到已经 ...
- 剑指offer系列38----滑动窗口的最大值(不懂????????????????????????????????????????????????)
[题目] 给定一个数组和滑动窗口的大小,找出所有滑动窗口里数值的最大值.例如,如果输入数组{2,3,4,2,6,2,5,1}及滑动窗口的大小3,那么一共存在6个滑动窗口,他们的最大值分别为{4,4,6 ...
- C#生成二维码示例
其实现在二维码越来越流行,网上也有很多生成二维码的类库.写一下WEB生成二维码注意事项吧! 目前C#生成二维码大部分都是使用ThoughtWorks.QRCode或者ZXing类库生成,主要说一下Th ...
- IO操作 第一篇 学习(转载)
问题8:如何使用通配符搜索指定目录内的所有文件: 解决方案: 使用DirectoryInfo.GetFiles方法的重载版本,它可以接受一个过滤表达式,返回FileInfo数组,另外它的参数还可以指定 ...