You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行Unetstack的2-node-network.groovy示例时报错求助

UnetStack示例运行错误排查

问题场景

我正在学习UnetStack,尝试通过运行示例熟悉它,但遇到两个问题:

  1. 执行官方命令 bin/unet samples/2-node-network.groovy 时,出现以下错误:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/home/peder/unet-3.4.0/lib/groovy-2.5.9.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
java.lang.IllegalArgumentException: object is not an instance of declaring class

预期输出应为:

2-node network
--------------

Node A: tcp://localhost:1101, http://localhost:8081/
Node B: tcp://localhost:1102, http://localhost:8082/
  1. 作为Linux新手,我手动安装Java和Groovy后直接用 groovy 2-node-network.groovy 运行,出现新错误:
2-node network
--------------

Node A: tcp://localhost:1101, http://localhost:8081/
Node B: tcp://localhost:1102, http://localhost:8082/

Caught: groovy.lang.MissingPropertyException: No such property: RealTimePlatform for class: 2-node-network
groovy.lang.MissingPropertyException: No such property: RealTimePlatform for class: 2-node-network
    at 2-node-network.run(2-node-network.groovy:17)

该示例在模拟器IDE中可正常运行,请问是否遗漏了关键配置?


问题原因与解决方法

第一个命令错误的原因及解决

错误源于Java版本与UnetStack自带的Groovy 2.5.9不兼容。Groovy 2.5.x在Java 11及以上版本会触发非法反射访问警告,甚至抛出IllegalArgumentException。

解决步骤:

  • 切换系统默认Java版本到Java 8:执行 update-alternatives --config java,按提示选择Java 8的选项。
  • 或在运行时指定Java 8路径:/path/to/java8/bin/java -jar bin/unet.jar samples/2-node-network.groovy(替换为你实际的Java 8安装路径)

第二个命令错误的原因及解决

直接用系统groovy命令运行时,未加载UnetStack的依赖库,导致找不到RealTimePlatform等专属类。而模拟器IDE会自动配置完整的类路径,因此能正常运行。

解决步骤:

  • 优先使用UnetStack自带的bin/unet脚本执行示例,只要解决Java版本兼容问题即可正常运行,无需额外配置。
  • 若需手动运行,需将UnetStacklib目录下所有Jar包加入类路径:groovy -cp "/home/peder/unet-3.4.0/lib/*" 2-node-network.groovy,但不推荐这种方式,易引发其他兼容问题。

内容的提问来源于stack exchange,提问作者Peder

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 22:00:29