【问题标题】:Run Groovy Scripts in IntelliJ fails在 IntelliJ 中运行 Groovy 脚本失败
【发布时间】:2017-06-08 10:37:25
【问题描述】:

我无法在 IntelliJ 中运行或调试 Groovy 脚本。我收到错误消息:Error: Could not find or load main class org.codehaus.groovy.tools.GroovyStarter。从 cmd 运行脚本可以正常工作(我使用的是 groovyc 和 groovy 命令)。

import org.apache.pdfbox.pdmodel.PDDocument
import org.fit.pdfdom.PDFDomTree
import org.w3c.dom.Document

// load the PDF file using PDFBox
PDDocument pdf = PDDocument.load(new java.io.File("file.pdf"))
// create the DOM parser
PDFDomTree parser = new PDFDomTree()
// parse the file and get the DOM Document
Document dom = parser.createDOM(pdf)

【问题讨论】:

标签: intellij-idea groovy


【解决方案1】:

我错过了 pom.xml 文件中的 https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all/2.4.12 依赖关系。错误已解决。谢谢大家的提示:)

【讨论】:

    【解决方案2】:

    创建Run Configuration (⌘N),并将Module 设置为包含所有依赖项的模块。

    【讨论】:

    • 你到底是什么意思?你能更详细地描述一下你的想法吗?
    • imgur.com/a/lyzFK 我应该在那里做什么?即使我不使用自己的类,脚本也会失败。
    • 你可以发布堆栈跟踪吗?
    • 我在运行控制台中没有堆栈跟踪。我只有这个文本:“C:\Program Files\Java\jdk1.8.0_131\bin\java”... 错误:无法找到或加载主类 org.codehaus.groovy.tools.GroovyStarter 进程已完成退出代码1
    【解决方案3】:

    我遇到了同样的问题,直到我做了下一个:

    1. 从“全局库”中删除了 groovy(不要忘记单击“应用”按钮 screenshot how to delete groovy
    2. 打开任何 groovy 文件,然后单击“配置 Groovy SDK” screenshot how to select groovy
    3. 选择了 groovy 安装的文件夹(见上面的截图)

    毕竟,我可以从 IDEA 运行/调试我的脚本

    【讨论】:

    • 这对我来说是一种祝福。基本上按照您的步骤,我为 Groovy 重新配置了相同的全局库。非常感谢。
    【解决方案4】:

    尝试创建你的脚本而不是 Groovy 类。 使用这种方式:

    Ctrl + Shift + A  -> Groovy Script  -> Set script name
    

    【讨论】:

    • 我有 Groovy 脚本,但在里面我有课和课后的一些代码。
    • 我认为你应该在单独的文件中创建类
    • 我将类移动到单独的文件,但我仍然遇到同样的问题:“错误:无法找到或加载主类 org.codehaus.groovy.tools.GroovyStarter”。
    • 我不认为代码是原因,因为每个脚本都因此错误而失败。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-18
    • 1970-01-01
    • 2013-09-22
    • 2012-11-29
    • 1970-01-01
    • 2019-01-31
    • 2013-11-06
    相关资源
    最近更新 更多