祝你们Java和gRPC大师们好运。
我一直在关注这个https://github.com/jpdna/gRPC-maven-helloworld,因为我正在学习使用Java的gRPC。
我能够使用mvn clean包编译它。但是当我在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类?
非常感谢你们!
发布于 2017-07-14 16:50:36
你需要一个protoc插件protoc-gen-grpc-java来在编译hello_world.proto时生成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>发布于 2017-08-02 06:51:04
我已经找到了我问题的答案。解决方案就是右键单击Eclipse上的项目,然后选择Run -> Maven generate-sources。一旦在目标文件夹中生成了源代码及其文件夹。右键单击这些生成的文件夹(带有源代码),然后选择Build Path --> Use as source Folder。错误将消失,因为它将能够解决丢失的类。
谢谢,祝你有愉快的一天=)!
https://stackoverflow.com/questions/44876754
复制相似问题