[英]How to run the akka grpc java example
Ok, following the prerequisites and instructions to use Java 8 the project creation works.好的,按照使用 Java 的先决条件和说明 8 项目创建工作。
sbt new akka/akka-grpc-quickstart-java.g8
Then continuing with the guide然后继续使用指南
./gradlew compileJava
works as well. ./gradlew compileJava
也可以。
but then ./gradlew --info runServer
fails with the folling errors/issues:但是随后
./gradlew --info runServer
因以下错误/问题而失败:
Task ':runServer' is not up-to-date because:
Task has not declared any outputs.
and和
Error: Main method not found in class com.example.helloworld.GreeterServer, please define the main method as:
public static void main(String[] args)
ORIGINAL POST:原帖:
I am having trouble getting the Akka-GRPC example to run.我无法运行 Akka-GRPC 示例。 I tried following this guide here but when I download the sample project it seems incomplete.
我在这里尝试按照本指南进行操作,但是当我下载示例项目时,它似乎不完整。
Thats the tree command output:那是树命令 output:
.
├── 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
There are no source files or gradlew oder pom.xml in the project structure.项目结构中没有源文件或 gradlew oder pom.xml。
Next I cloned the repository of that example from GitHub and followed the instructions in readme, mainly the command sbt new akka/akka-grpc-quickstart-java.g8
.接下来,我从 GitHub 克隆了该示例的存储库,并按照自述文件中的说明进行操作,主要是命令
sbt new akka/akka-grpc-quickstart-java.g8
。
$ sbt new akka/akka-grpc-quickstart-java.g8
[info] Loading settings for project akka-grpc-quickstart-java-g8-build from paradox.sbt,giter8.sbt ...
[info] 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.
then I went into the project/sources folder./src/main/g8/ where the source files are located and tried to follow the instructions from the guide from in there.然后我进入源文件所在的 project/sources 文件夹./src/main/g8/ 并尝试按照那里的指南中的说明进行操作。 That also did not work because of some properties errors:
由于某些属性错误,这也不起作用:
Before that I had to set another gradle version (6.1.1, was 4.5.1) in./gradle/wrapper/gradle-wrapper.properties to make it compatible with Java 13.在此之前,我必须在./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
Trying to at least temporarily get this to work i hardcoded the properties into the build.gradle file:为了至少暂时让它工作,我将属性硬编码到 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'
But that also only got me so far:但这也只是让我到目前为止:
$ ./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
Again could not include whole stacktrace because of character limit.由于字符限制,再次无法包含整个堆栈跟踪。
What am I missing?我错过了什么? Which approach should I pursue further?
我应该进一步采用哪种方法?
EDIT: Meanwhile, the pull request was accepted and the main repo ( https://github.com/akka/akka-grpc-quickstart-java.g8 ) is up-to-date.编辑:同时,拉取请求被接受,主回购( https://github.com/akka/akka-grpc-quickstart-java.g8 )是最新的。
I downloaded the project using sbt new..., but there was an error within the pom.xml (fixed version: https://github.com/olitazl/akka-grpc-quickstart-java.g8 )我使用 sbt new... 下载了项目,但是 pom.xml 中出现错误(固定版本: https://github.com/olitazl/akka-grpc-quickstart-java.g8 )
The problem of the example project are missing public
modifier inside the GreeterServer
class.示例项目的问题是缺少 GreeterServer 内部的
public
修饰符GreeterServer
。
Therefore, you have to add public
to the GreeterServer class and the method main
within.因此,您必须将
public
添加到 GreeterServer class 和其中的方法main
。
public class GreeterServer ...
public static void main(...)
If you recreate your project from my repo, the problem is fixed there as well.如果您从我的存储库重新创建您的项目,问题也已解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.