zl程序教程

您现在的位置是:首页 >  其他

当前栏目

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

错误IDEA 报错 not 记录 编译 or be
2023-09-14 09:07:28 时间





一、错误记录



运行

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 代码 , 均不可运行 ;