0

我正在尝试使用 scalaPB 的官方示例来实现简单的服务器客户端应用程序。scala 代码可以在他们的gitHub上找到

但是,当我尝试运行它时,object helloworld is not a member of package io.grpc.examples.helloworld当我尝试使用import io.grpc.examples.helloworld.helloworld.{foo}.

我的 build.sbt 文件:

name := "Distributed sorting"
version := "0.1"
scalaVersion := "2.13.7"
libraryDependencies ++= Seq(
    "io.grpc" % "grpc-netty" % scalapb.compiler.Version.grpcJavaVersion,
    "com.thesamet.scalapb" %% "scalapb-runtime-grpc" % scalapb.compiler.Version.scalapbVersion
)

Compile / PB.targets := Seq(
  scalapb.gen() -> (Compile / sourceManaged).value / "scalapb"
)

我的文件如下所示:

├── build.sbt
├── project
│   ├── build.properties
│   ├── scalapb.sbt
│   └── target
        ├── ...
└── src/main
    ├── protobuf
        ├── hello.proto
    └── scala/io/grpc/examples/helloworld
        ├── HelloWorldClient.scala
        └── HelloWorldServer.scala
4

1 回答 1

2

首先,我推荐使用Akka gRPC而不是直接使用 ScalaPB。文档非常清晰,并且有一个giter8 配置可用于使用sbt new.

其次,那个 gitHub 中的代码看起来不像官方的示例代码。它说它是“从 grpc java 翻译的”,这可能不是你想要的。

最后,在您看到的具体问题上,由 scalaPB 生成的存根位于一个包中,该包的名称在proto文件中给出。示例文件有

package com.example.protos

所以存根将在com.example.protos.Greeter.

于 2021-11-23T07:20:34.437 回答