代码之家  ›  专栏  ›  技术社区  ›  Artanis Zeratul

设置gRPC Java

  •  1
  • Artanis Zeratul  · 技术社区  · 8 年前

    大家好,Java和gRPC专家们。

    https://github.com/jpdna/gRPC-maven-helloworld

    但当我在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类?

    非常感谢你们!

    2 回复  |  直到 7 年前
        1
  •  3
  •   Z fp    8 年前

    你需要一个 protoc 插件 protoc-gen-grpc-java GreeterGrpc.class 当complie hello_world.proto .

    或者你可以使用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>
    
        2
  •  1
  •   Artanis Zeratul    7 年前

    我已经找到了问题的答案……解决方案是在Eclipse上右键单击项目,然后选择运行方式-->Maven生成源。在目标文件夹中生成源代码及其文件夹后。右键单击那些生成的文件夹(带有源代码),然后,构建路径-->用作源文件夹。错误将消失,因为它将能够解决丢失的类。