Java 使用grape从groovy脚本运行main类

Java 使用grape从groovy脚本运行main类,java,groovy,pdfbox,grape,Java,Groovy,Pdfbox,Grape,我想通过使用@Grab运行java类的main方法,以便自动处理需求。更具体地说,我想运行pdfbox示例 我编写了以下groovy脚本 #!/usr/bin/env groovy @Grab('org.apache.pdfbox:pdfbox-examples:2.0.20') import org.apache.pdfbox.examples.util.RemoveAllText RemoveAllText.main(args) main的@Grab、import和执行似乎起了作用。但ma

我想通过使用@Grab运行java类的main方法,以便自动处理需求。更具体地说,我想运行pdfbox示例

我编写了以下groovy脚本

#!/usr/bin/env groovy
@Grab('org.apache.pdfbox:pdfbox-examples:2.0.20')
import org.apache.pdfbox.examples.util.RemoveAllText
RemoveAllText.main(args)
main的@Grab、import和执行似乎起了作用。但main似乎反复回忆自己,因此出现如下StackOverflower错误

Caught: java.lang.StackOverflowError
java.lang.StackOverflowError
        at RemoveAllText.main(RemoveAllText.groovy)
        at RemoveAllText$main.call(Unknown Source)
        at RemoveAllText.run(RemoveAllText.groovy:5)
        at RemoveAllText.main(RemoveAllText.groovy)
        ...
我是groovy新手,所以我不确定自己做错了什么。我想做的事可能吗?如果可能的话,怎么做

为了使示例完全可复制,当我使用在和使用groovy 2.4.16版上找到的pdf文件时,我遇到了上述错误,该版本是使用Ubuntu 18.04中的默认存储库安装的。命令运行将是

groovy RemoveAllText.groovy helloworld.pdf helloworld_out.pdf
如果我手动下载所需的jar文件并运行

java -cp pdfbox-2.0.20.jar:commons-logging-1.2.jar:pdfbox-examples-2.0.20.jar org.apache.pdfbox.examples.util.RemoveAllText helloworld.pdf helloworld_out.pdf

它可以正常工作。

将脚本从RemoveAllText.groovy重命名为其他脚本,一切都应该正常


问题是groovy脚本生成的类名与Apache类相同。

我想知道这到底是如何工作的,因为您的链接指向主干,主干使用的API与2.0.20不同。您需要的是:args为空时会发生什么。使用消息出现了吗?仅供参考-它运行良好,使用groovy 2.4.7时工作正常。我尝试同时使用RemoveAllText.main和new RemoveAllText().main-这两种方法都有效。请将脚本从
RemoveAllText.groovy
重命名为其他名称,一切都应该正常。您的groovy脚本生成的类名与Apache类相同,这是一个问题。我非常确定——我的脚本名为Differentilty,相同的名称可以解释无限循环。