在IntelliJ中运行Groovy脚本失败

时间:2017-06-08 10:37:25

标签: intellij-idea groovy

我无法在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)

4 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:3)

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

See image

答案 2 :(得分:1)

在遇到下一个问题之前,我遇到了同样的问题:

  1. 从“全球图书馆”中删除了常规(别忘了单击“应用”按钮 screenshot how to delete groovy
  2. 打开任何groovy文件,然后单击“配置Groovy SDK” screenshot how to select groovy
  3. 选择安装Groovy的文件夹(请参见上面的屏幕截图)

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

答案 3 :(得分:-1)

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

Ctrl + Shift + A  -> Groovy Script  -> Set script name
相关问题