简体   繁体   English

有没有办法在 Java 8 运行时中使用 flatc 生成的类?

[英]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.

相关问题 Spring 4.3.5我可以使用带有@ModelAttribute批注的运行时生成的Java类吗? - Spring 4.3.5 can i use runtime-generated java classes with @ModelAttribute annotation? 在Java运行时调用不同类的最佳方法 - Best way to call different classes at runtime in Java 在Java Web应用程序中将运行时生成的类存储在哪里? - Where to store classes generated at runtime in a java web application? 有没有一种方法可以基于包中的所有Java源文件生成哈希,然后在运行时在日志消息中使用该值? - Is there a way to generate a hash based on all the java source files in a package and then use that value within a log message at runtime? 如何在一个活动中使用Java类? - How to use java classes within one activity? 用Java加载类运行时 - Loading classes runtime in Java 无法使用由 java 类中的 groovy @Delegate 生成的方法 - Not able to use methods generated by groovy @Delegate from java classes JavaCC:我希望从动态生成的jj文件生成java类,并在运行时编译它们 - JavaCC: I wish to generate java classes from dynamically generated jj files and to compile them at runtime 如何在Matlab中使用用户定义的Java类? - How do I use user defined Java classes within Matlab? Java:在运行时将类作为参数传递 - Java: Passing classes as parameters at runtime
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM