如何运行Akka Grpc Java示例

2019年1月3日 12点热度 0条评论

好的,按照使用Java 8的先决条件和说明进行项目创建。
sbt new akka/akka-grpc-quickstart-java.g8
然后继续guide
./gradlew compileJava也可以。

但是./gradlew --info runServer失败,并出现以下错误/问题:

Task ':runServer' is not up-to-date because:
Task has not declared any outputs.


Error: Main method not found in class com.example.helloworld.GreeterServer, please define the main method as:
   public static void main(String[] args)


原始帖子:

我无法运行Akka-GRPC示例。

我尝试遵循
this guide here,但是当我下载示例项目时,它似乎不完整。

那是树命令输出:

.
├── build.sbt
├── project
│   ├── build.properties
│   └── plugins.sbt
├── sbt
├── sbt.bat
└── sbt-dist
    ├── bin
    │   ├── sbt
    │   ├── sbt.bat
    │   ├── sbt-launch.jar
    │   └── sbt-launch-lib.bash
    └── conf
        ├── sbtconfig.txt
        └── sbtopts

4 directories, 11 files

在项目结构中没有源文件或gradlew oder pom.xml。

接下来,我克隆了
repository of that example from GitHub并按照自述文件中的说明进行操作,主要是命令
sbt new akka/akka-grpc-quickstart-java.g8

$ sbt new akka/akka-grpc-quickstart-java.g8
Loading settings for project akka-grpc-quickstart-java-g8-build from paradox.sbt,giter8.sbt ...
Loading project definition from /home/johannes/IdeaProjects/akka-grpc-quickstart-java.g8/project error: error while loading String, class file '/modules/java.base/java/lang/String.class' is broken (class java.lang.NullPointerException/null) [error] java.io.IOError: java.lang.RuntimeException: /packages cannot be represented as URI ...//had to remove stacktrace was too long for this post [error] at xsbt.boot.Boot.main(Boot.scala) Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? [error] java.io.IOError: java.lang.RuntimeException: /packages cannot be represented as URI [error] Use 'last' for the full log.

然后我进入了位于源文件所在的project / sources文件夹./src/main/g8/,并尝试按照该指南中的指导进行操作。

由于某些属性错误,这也不起作用:

在此之前,我必须在./gradle/wrapper/gradle-wrapper.properties中设置另一个gradle版本(6.1.1,为4.5.1),以使其与Java 13兼容。

$ ./gradlew compileJava

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'g8'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not find gradle.plugin.com.lightbend.akka.grpc:akka-grpc-gradle-plugin:$akka_grpc_version$.
     Searched in the following locations:
       - file:/home/johannes/.m2/repository/gradle/plugin/com/lightbend/akka/grpc/akka-grpc-gradle-plugin/$akka_grpc_version$/akka-grpc-gradle-plugin-$akka_grpc_version$.pom
       - https://plugins.gradle.org/m2/gradle/plugin/com/lightbend/akka/grpc/akka-grpc-gradle-plugin/$akka_grpc_version$/akka-grpc-gradle-plugin-$akka_grpc_version$.pom
     Required by:
         project :

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 4s

尝试至少暂时使它起作用,我将属性硬编码到build.gradle文件中:

     //classpath 'gradle.plugin.com.lightbend.akka.grpc:akka-grpc-gradle-plugin:$akka_grpc_version$'
     classpath 'gradle.plugin.com.lightbend.akka.grpc:akka-grpc-gradle-plugin:0.7.3'

但这也让我到目前为止:

$ ./gradlew compileJava

FAILURE: Build failed with an exception.

* Where:
Build file '/home/johannes/IdeaProjects/akka-grpc-quickstart-java.g8/src/main/g8/build.gradle' line: 20

* What went wrong:
A problem occurred evaluating root project 'g8'.
> Failed to apply plugin [id 'com.google.protobuf']
   > Could not create an instance of type com.google.protobuf.gradle.ProtobufSourceDirectorySet.
      > 'void org.gradle.api.internal.file.DefaultSourceDirectorySet.<init>(java.lang.String, java.lang.String, org.gradle.api.internal.file.FileResolver, org.gradle.api.internal.file.collections.DirectoryFileTreeFactory)'

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

再次由于字符限制而不能包括整个stacktrace。

我想念什么?

我应该采取哪种方法?

解决方案如下:

编辑:同时,拉请求已被接受,主仓库(https://github.com/akka/akka-grpc-quickstart-java.g8)是最新的。

我使用sbt new下载了项目...,但是pom.xml中存在错误(固定版本:https://github.com/olitazl/akka-grpc-quickstart-java.g8)

示例项目的问题是public类内缺少GreeterServer修饰符。

因此,必须将public添加到GreeterServer类中,并在其中添加方法main

    public class GreeterServer ...
    public static void main(...)

如果您从我的仓库中重新创建项目,该问题也将在那里解决。