欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

【错误记录】IntelliJ IDEA 编译 Groovy 报错 ( GroovyRuntimeException: This script or class could not be run. )

发布时间:2025/6/17 编程问答 64 豆豆
生活随笔 收集整理的这篇文章主要介绍了 【错误记录】IntelliJ IDEA 编译 Groovy 报错 ( GroovyRuntimeException: This script or class could not be run. ) 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

文章目录

  • 一、错误记录
  • 二、问题分析





一、错误记录



运行

class Student1 { }

Groovy 代码 , 会报错 ;


报错信息 :

groovy.lang.GroovyRuntimeException: This script or class could not be run. It should either: - have a main method, - be a JUnit test or extend GroovyTestCase, - implement the Runnable interface, - or be compatible with a registered script runner. Known runners:* <none>





二、问题分析



只有符合如下要求的 Groovy 代码可以运行 :

  • 有 main 函数 ;

  • 测试用例 , 作为JUnit测试或扩展GroovyTestCase ;

  • 线程相关 , 实现Runnable接口 ;

  • 与注册的脚本运行程序兼容 ;

其它情况的 Groovy 代码 , 均不可运行 ;

总结

以上是生活随笔为你收集整理的【错误记录】IntelliJ IDEA 编译 Groovy 报错 ( GroovyRuntimeException: This script or class could not be run. )的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。