use*_*693 3 java rpc compilation grpc
我在弄清楚如何编译GRPC Java服务器时遇到了很多麻烦.我查看了整个grpc.io网站,我发现最接近的是:http://www.grpc.io/docs/#quick-start,我在哪里运行
../gradlew -PskipCodegen=true installDist构建,并
./build/install/grpc-examples/bin/hello-world-client运行客户端.这一切都有效,但仅适用于hello-world教程.我不知道如何为我自己的客户端/服务器执行此操作.我能够使用.proto文件生成客户端/服务器protobufs.我查看了自述文件和Java教程,在编写实际服务器(和客户端)之后无法找到如何编译它们
https://github.com/grpc/grpc-java/blob/master/examples/README. md
(无法链接java教程,因为我没有足够的声誉).除非缺少文档,否则有没有人知道如何编译实现从.proto文件生成的GRPC类的服务器和客户端?我确实花了很多时间搜索.非常感谢任何建议,谢谢.
小智 6
也有类似的问题,确保:
protoc,即将下载可执行文件并将其配置为操作系统的环境变量.该build.gradle文件,请确保包含protobuf-gradle-plugin:
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'com.google.protobuf'
ext.grpcVersion = '1.0.1'
ext.protobufVersion = '3.0.2'
buildscript {
repositories { mavenCentral() }
dependencies {
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.0' }
}
repositories {
mavenCentral()
}
dependencies {
compile "com.google.protobuf:protobuf-java:${protobufVersion}"
compile "io.grpc:grpc-all:${grpcVersion}"
}
protobuf {
protoc { artifact = "com.google.protobuf:protoc:${protobufVersion}" }
plugins { grpc { artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" } }
generateProtoTasks { ofSourceSet('main')*.plugins { grpc { } } }
}
idea {
module {
sourceDirs += file("${protobuf.generatedFilesBaseDir}/main/java");
sourceDirs += file("${protobuf.generatedFilesBaseDir}/main/grpc");
}
}
Run Code Online (Sandbox Code Playgroud)你的proto档案:
syntax = "proto3";
package com.company.project;
service CompanyService{
rpc call(RequestMessage) returns (ResponseMessage) {}
}
Run Code Online (Sandbox Code Playgroud)运行gradle clean build,它应该为您生成服务和客户端类CompanyService.
该idea插件,用于告诉IntelliJ将其识别src/main/proto为源集.
实际执行的客户端和服务器,你将需要进行实施,在教程GRPC提到的,然后应用application插件,以便正确生成可执行jar
//build.grdle code...
apply plugin: 'application'
mainClassName = 'com.company.project.MainClass'
jar { manifest { attributes('Main-Class' : mainClassName) } }
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
3474 次 |
| 最近记录: |