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(远程过程调用) 的架构最常见的是"动态代理"方式,事先定义好接口,用一个代理假装实现了这个接口(真正的实现放在服务端),供客户端调用,代理内部将该方法调用封装成一个网络请求 ...
随机推荐
- 反射矩阵(reflection matrix)推导
设平面为(nx,ny,nz,d),则以此平面为镜面的列主序反射矩阵如下: 推导如下: 一,平面的表示: 如图所示,过点p,法向量为n的平面,可表示为: np+d=0 其中d为平面到原点的有向距离.如果 ...
- 在没有spineRunTime情况下手动使用spine数据
用spine做了一些简单UI动画,结果发现游戏用的cocos2dx版本太低了,无法集成spineRunTime,无奈只好把spine记下的关键帧数据抄到一个txt文件中,然后读取txt,再自己写代码播 ...
- Linux How to add a new disk to LVM
转自:http://blog.itpub.net/7191998/viewspace-772060/ 1.check old diskspace and device listdf -halfree ...
- ActionContext详解
ActionContext ActionContext是Action的上下文,Struts2自动在其中保存了一些在Action执行过程中所需的对象,比如session, parameters, ...
- Externalizable接口 序列化
Java默认的序列化机制非常简单,而且序列化后的对象不需要再次调用构造器重新生成,但是在实际中,我们可以会希望对象的某一部分不需要被序列化,或者说一个对象被还原之后, 其内部的某些子对象需要重新创建, ...
- HTML5跨浏览器表单及HTML5表单的渐进增强
HTML5跨浏览器表单 http://net.tutsplus.com/tutorials/html-css-techniques/how-to-build-cross-browser-html5-f ...
- nova分析(4)—— nova-cells
cells的功能允许用户以更分散的方式去扩展OpenStack计算云而无需使用复杂的技术,比如数据库和消息队列的集群.它的目的是支持非常大规模的部署. 当启用了此功能,在OpenStack计算云中的主 ...
- ios外派—本公司长年提供ios程序员外派业务(北京动点软件,可签合同)
北京动点飞扬长年提供ios工程师外派业务. 我公司程序员平均技术情况如下: 1.二年以上iPhone/ipad开发经验:2.熟练使用Xcode.Objective C编码技能:3.熟悉iOS开发框架, ...
- 【mysql】SQL常用指令
常用操作指令 show databases;显示所有的数据库: use dbName; 使用指定数据库 show tables; 显示所有的数据表: desc tableName; 查看数据表的字段信 ...
- pgsql 9.4修改数据库只读
先进入psql 切换到目标数据库 \c mydb 对于老表 grant usage on schema public to $read_only_user; grant select on all t ...