[英]Is there a way to use flatc generated classes within a Java 8 runtime?
I have working code that runs fine in OpenJDK Java 9, but throws the NoSuchMethodError below when run in OPenJDK Java 8. Even when flatc is built on a system with Java 8 I still get this error.我有在 OpenJDK Java 9 中运行良好的工作代码,但是在 OPenJDK Java 8 中运行时会抛出下面的 NoSuchMethodError。即使 flatc 是在带有 Java 8 的系统上构建的,我仍然会收到此错误。 Is there any way to generate classes that will work in Java 8?
有没有办法生成可以在 Java 8 中工作的类?
Exception in thread "main" java.lang.NoSuchMethodError: java.nio.ByteBuffer.position(I)Ljava/nio/ByteBuffer;
at com.google.flatbuffers.FlatBufferBuilder.createString(FlatBufferBuilder.java:605)
at jeromq_and_flatbuffers.io.MonsterIO.writeTo(MonsterIO.java:54)
at jeromq_and_flatbuffers.io.MonsterIO.writeTo(MonsterIO.java:1)
at jeromq_and_flatbuffers.core.MonsterPublisher.sendMessage(MonsterPublisher.java:80)
at jeromq_and_flatbuffers.core.MonsterPublisher.run(MonsterPublisher.java:104)
at jeromq_and_flatbuffers.core.Main.lambda$0(Main.java:46)
at java.util.Optional.ifPresent(Optional.java:159)
at jeromq_and_flatbuffers.core.Main.main(Main.java:46)
I realize there were a number of NIO improvements in Java 9, but my network IT has constrained us to Java 8.我意识到 Java 9 中有许多 NIO 改进,但我的网络 IT 限制了我们使用 Java 8。
A solution is to either not use downloaded Flatbuffers 2.0.0 dependency from Maven central repo, which is built with Java 9 or higher.一个解决方案是不使用从 Maven 中央存储库下载的 Flatbuffers 2.0.0 依赖项,它是用 Java 9 或更高版本构建的。 Instead, build Flatbuffers jar from source by downloading Flatbuffers source, then executing maven package in the top level directory, within a Java 8 environment.
相反,通过下载 Flatbuffers 源代码从源代码构建 Flatbuffers jar,然后在 Java 8 环境中执行顶级目录中的 maven 包。 Then take the jar in target and use that in your app.
然后在目标中取出 jar 并在您的应用程序中使用它。 This got me past the error.
这让我克服了错误。
A better solution is to use Flatbuffers 2.0.2 or later, which fixes the problem.更好的解决方案是使用 Flatbuffers 2.0.2 或更高版本,这可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.