Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Groovy 传播多个类的依赖关系_Groovy_Groovy Grab - Fatal编程技术网

Groovy 传播多个类的依赖关系

Groovy 传播多个类的依赖关系,groovy,groovy-grab,Groovy,Groovy Grab,这个类位于文件StreamingPOIWriter.groovy @Grapes([ @Grab(group='org.apache.poi', module='poi', version='3.14'), @Grab(group='org.apache.poi', module='poi-ooxml', version='3.14'), @Grab(group='org.apache.poi', module='poi-ooxml-schemas', version='

这个类位于文件
StreamingPOIWriter.groovy

@Grapes([
    @Grab(group='org.apache.poi', module='poi', version='3.14'),
    @Grab(group='org.apache.poi', module='poi-ooxml', version='3.14'),
    @Grab(group='org.apache.poi', module='poi-ooxml-schemas', version='3.14')
])

import org.apache.poi.xslf.usermodel.XMLSlideShow
import org.apache.poi.xslf.usermodel.XSLFSlide

class StreamingPOIWriter {

    XMLSlideShow presentation

    def withPresentation() {
        presentation = new XMLSlideShow()
        this
    }

    def write(filename) {
        presentation.write(new FileOutputStream(filename))
    }

    def withSlide() {
        XSLFSlide slide = presentation.createSlide()
        this
    }
}
new StreamingPOIWriter()
    .withPresentation()
        .withSlide()
            .write("presentation.pptx")
我使用
groovyc
编译了它

但是当我决定在另一个文件中创建它的实例时-
script.groovy

@Grapes([
    @Grab(group='org.apache.poi', module='poi', version='3.14'),
    @Grab(group='org.apache.poi', module='poi-ooxml', version='3.14'),
    @Grab(group='org.apache.poi', module='poi-ooxml-schemas', version='3.14')
])

import org.apache.poi.xslf.usermodel.XMLSlideShow
import org.apache.poi.xslf.usermodel.XSLFSlide

class StreamingPOIWriter {

    XMLSlideShow presentation

    def withPresentation() {
        presentation = new XMLSlideShow()
        this
    }

    def write(filename) {
        presentation.write(new FileOutputStream(filename))
    }

    def withSlide() {
        XSLFSlide slide = presentation.createSlide()
        this
    }
}
new StreamingPOIWriter()
    .withPresentation()
        .withSlide()
            .write("presentation.pptx")
当我发现使用
groovy script.groovy运行它时,我得到了这个错误

Caught: java.lang.NoClassDefFoundError: org/apache/poi/xslf/usermodel/XMLSlideShow
java.lang.NoClassDefFoundError: org/apache/poi/xslf/usermodel/XMLSlideShow
        at script.run(script.groovy:2)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.xslf.usermodel.XMLSlideShow
        ... 1 more
似乎无法找到
StreamingPOIWriter
所需的依赖项。 如何将它们传播到
script.groovy


StreamingPOIWriter.groovy
script.groovy
在同一个文件夹中。

好吧,这不是Grapes的初衷。正如您可能发现的那样,它们旨在运行单个脚本。如果您真的想做您现在正在做的事情,那么还可以将@Grapes注释添加到
script.groovy


否则,如果您要构建更复杂的东西,我建议使用Gradle
gradleinit
,在您的情况下,
gradleinit--type groovy library
可能是您的朋友。

好吧,这不是Grapes的初衷。正如您可能发现的那样,它们旨在运行单个脚本。如果您真的想做您现在正在做的事情,那么还可以将@Grapes注释添加到
script.groovy


否则,如果您要构建更复杂的东西,我建议使用Gradle
gradleinit
,在您的例子中,
gradleinit--type groovy library
可能是您的朋友。

我认为它与脚本有关。但我假设它可以以某种方式使用它的依赖项……毕竟它下载到
.m2
文件夹中。我认为它与脚本相关。但我假设它可以以某种方式使用它的依赖项……毕竟它将它下载到
.m2
文件夹中。