【问题标题】:object is not a member of package对象不是包的成员
【发布时间】:2022-01-01 15:53:36
【问题描述】:

我正在尝试使用 scalaPB 的official example 实现简单的服务器-客户端应用程序。 scala 代码在他们的gitHub

但是,当我尝试运行它时,当我尝试使用 import io.grpc.examples.helloworld.helloworld.{foo} 导入任何内容时,我不断收到错误 object helloworld is not a member of package io.grpc.examples.helloworld

我的 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

【问题讨论】:

    标签: scala protocol-buffers grpc scalapb


    【解决方案1】:

    首先,我推荐使用Akka gRPC,而不是直接使用ScalaPB。文档很清楚,有一个giter8 config 可以用来创建一个使用sbt new 的示例项目。

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

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

    package com.example.protos
    

    所以存根将位于com.example.protos.Greeter

    【讨论】:

      猜你喜欢
      • 2018-02-21
      • 2012-12-20
      • 2018-09-10
      • 2021-12-06
      • 2021-06-03
      • 2016-02-29
      • 2018-10-25
      • 2016-09-25
      • 2020-09-19
      相关资源
      最近更新 更多