2017-07-03 98 views
0

对你来说很好的一天Java和gRPC专家在那里。设置gRPC Java

我一直在关注这个https://github.com/jpdna/gRPC-maven-helloworld,因为我正在学习使用Java的gRPC。

我能够使用mvn clean package进行编译。 但是当我装在Eclipse项目中,该文件:

org.jpdna.grpchello.HelloWorldServer 

正在寻找类“GreeterGrpc”。

我试图在终端中执行这样的:

$ protoc --java_out=/gRPC-maven-helloworld/src/main/java hello_world.proto 

它产生以下类:

- HelloRequest.java 
    - HelloRequestOrBuilder.java 
    - HelloResponse.java 
    - HelloResponseOrBuilder.java 
    - HelloWorldProto.java 

但是,没有GreeterGrpc.java其被定义为在该项目的服务。 如果你不介意我问,我想知道如何创建或生成这个GreeterGrpc.java类?

非常感谢你们!

回答

0

我已经找到了答案,我的问题......解决方案仅仅是对Eclipse的项目点击右键,然后选择Run As - > Maven的产生来源。一旦在目标文件夹中生成源代码及其文件夹。右键单击那些生成的文件夹(包含源代码),然后点击Build Path - >用作源文件夹。错误将消失,因为它将能够解决缺失的类。

谢谢你,祝你有美好的一天=)!

1

当编译hello_world.proto时,您需要一个protoc插件protoc-gen-grpc-java生成GreeterGrpc.class

或者您可以使用maven插件来实现相同的目的。 我Maven的配置:

<dependency> 
    <groupId>io.grpc</groupId> 
    <artifactId>grpc-all</artifactId> 
    <version>1.0.3</version> 
</dependency> 


<extension> 
    <groupId>kr.motd.maven</groupId> 
    <artifactId>os-maven-plugin</artifactId> 
    <version>1.5.0.Final</version> 
</extension> 


<plugin> 
<artifactId>exec-maven-plugin</artifactId> 
<groupId>org.codehaus.mojo</groupId> 
<executions> 
    <execution> 
     <id>uncompress</id> 
     <phase>install</phase> 
     <goals> 
      <goal>exec</goal> 
     </goals> 
     <configuration> 
      <executable>${basedir}/bin/upgrade.sh ${environment}</executable> 
     </configuration> 
    </execution> 
</executions> 
</plugin> 


<plugin> 
    <groupId>org.xolstice.maven.plugins</groupId> 
    <artifactId>protobuf-maven-plugin</artifactId> 
    <version>0.5.0</version> 
    <configuration> 
<protocArtifact>com.google.protobuf:protoc:3.1.0:exe:${os.detected.classifier}</protocArtifact> 
     <pluginId>grpc-java</pluginId> 
     <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.0.3:exe:${os.detected.classifier}</pluginArtifact> 
    </configuration> 
    <executions> 
     <execution> 
      <goals> 
       <goal>compile</goal> 
       <goal>compile-custom</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 
+0

@Z fp,感谢您花时间回答。但我想我找到了我的问题的答案。你可以在下面找到它。谢谢=)! –