我添加了如下的maven配置。
<plugin>
<groupId>com.github.os72</groupId>
<artifactId>protoc-jar-maven-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.0.0</protocArtifact>
<inputDirectories>
<include>src/main/protobuf</include>
</inputDirectories>
<outputTargets>
<outputTarget>
<type>java</type>
<outputDirectory>src/main/java</outputDirectory>
</outputTarget>
<outputTarget>
<type>grpc-java</type>
<outputDirectory>src/main/java</outputDirectory>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.0.1</pluginArtifact>
</outputTarget>
</outputTargets>
</configuration>
</execution>
</executions>
</plugin>
我正在通过“ mvn protoc-jar:run”执行它,但是它跳过了grpc服务存根,只将“消息”隐蔽到Java代码中。
输出是
[INFO] Protoc version: 3.5.1
protoc-jar: protoc version: 3.5.1, detected platform: osx-x86_64 (mac os x/x86_64)
protoc-jar: embedded: bin/3.5.1/protoc-3.5.1-osx-x86_64.exe
protoc-jar: executing: [/var/folders/9y/w8qrc__9513dv57323sjdlmw0000gn/T/protocjar320569499467403052/bin/protoc.exe, --version]
libprotoc 3.5.1
[INFO] Protoc command: /var/folders/9y/w8qrc__9513dv57323sjdlmw0000gn/T/protocjar320569499467403052/bin/protoc.exe
[INFO] Input directories:
[INFO] /Users/dev/learn/proto-java/src/main/protobuf
[INFO] Output targets:
[INFO] java: /Users/dev/learn/proto-java/target/generated-sources (add: main, clean: false, plugin: null, outputOptions: null)
[INFO] Processing (java): helloworld.proto
protoc-jar: executing: [/var/folders/9y/w8qrc__9513dv57323sjdlmw0000gn/T/protocjar320569499467403052/bin/protoc.exe, -I/Users/dev/learn/proto-java/src/main/protobuf, --java_out=/Users/dev/learn/proto-java/target/generated-sources, /Users/dev/learn/proto-java/src/main/protobuf/helloworld.proto]
[INFO] Adding generated classes to classpath
我有一个简单的原始文件定义为
syntax = "proto3";
option java_multiple_files = true;
option java_package = "-.-.-.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";
package helloworld;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
rpc SayHelloAgain (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}
我仅输出生成为HelloReply,HelloReplyOrBuilder,HelloRequest,HelloRequestOrBuilder,HelloWorldProto的文件。缺少Greeter Grpc服务存根。我是Maven的新手,我错过了什么。
答案 0 :(得分:1)
使用Maven阶段... https://maven.apache.org/ref/3.5.2/maven-core/lifecycles.html
mvn generate-sources
将生成您的GreeterRpc
答案 1 :(得分:0)
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.4.0:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<id>protobuf-generate</id>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>