加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

如何从命令行运行Groovy脚本作为Java?

发布时间:2020-12-14 16:35:56 所属栏目:大数据 来源:网络整理
导读:我正在尝试使用groovyc,但有些是不对的: echo println("Hello world") test.groovygroovy test.groovyHello worldgroovyc test.groovyjava -cp C:utilsgroovy-1.8.1embeddablegroovy-all-1.8.1.jar testError: Could not find or load main class testd
我正在尝试使用groovyc,但有些是不对的:

>echo println("Hello world") > test.groovy
>groovy test.groovy
Hello world
>groovyc test.groovy
>java -cp C:utilsgroovy-1.8.1embeddablegroovy-all-1.8.1.jar test
Error: Could not find or load main class test

>dir test.class
...

11/10/2011  02:54 PM             7,104 test.class

我失踪了什么

解决方法

当您使用-cp switch指定类路径时,其默认值(当前目录)将被覆盖,因此JVM找不到您的类.

将当前目录添加到classpath,一切正常:

>java -cp C:utilsgroovy-1.8.1embeddablegroovy-all-1.8.1.jar;. test
Hello,world

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读