在Groovy中的jar文件中导入错误

时间:2022-02-08 12:23:58

Similar to this question I have a small groovy test script that basically uses the example from opencsv java library:

与此问题类似,我有一个小的groovy测试脚本,基本上使用opencsv java库中的示例:

import au.com.bytecode.opencsv.CSVReader

CSVReader reader = new CSVReader(new FileReader("GroovyTest.csv"));
    String [] nextLine;
    while ((nextLine = reader.readNext()) != null) {
        // nextLine[] is an array of values from the line
        System.out.println(nextLine[0] + nextLine[1] + "etc...");
    }

I keep getting the error "unable to resolve class au.com.bytecode.opencsv.CSVReader". I even put the opencsv jar file in the same directory as my script but it does not recognize it. I assumed this was a classpath issue so I tried with -cp tag only to receive the same error.

我一直收到错误“无法解析类au.com.bytecode.opencsv.CSVReader”。我甚至将opencsv jar文件放在与我的脚本相同的目录中,但它无法识别它。我认为这是一个类路径问题,所以我尝试使用-cp标记只接收相同的错误。

I am running from the command line as $ groovy testg.groovy

我从命令行运行$ groovy testg.groovy

2 个解决方案

#1


1  

Groovy won't automatically pick up jars from the current working directory. You can either call groovy with a classpath (-cp <classpath>), or put the jar file ${user.home}/.groovy/lib.

Groovy不会自动从当前工作目录中获取jar。您可以使用类路径调用groovy(-cp ),也可以将jar文件$ {user.home} / .groovy / lib。

Your example worked for me when I launched it like this:

当我像这样启动它时,你的例子对我有用:

groovy -cp opencsv-2.2/deploy/opencsv-2.2.jar testg.groovy

#2


-1  

import au.com.bytecode.opencsv.*

The import is working fine for me

导入对我来说很好

#1


1  

Groovy won't automatically pick up jars from the current working directory. You can either call groovy with a classpath (-cp <classpath>), or put the jar file ${user.home}/.groovy/lib.

Groovy不会自动从当前工作目录中获取jar。您可以使用类路径调用groovy(-cp ),也可以将jar文件$ {user.home} / .groovy / lib。

Your example worked for me when I launched it like this:

当我像这样启动它时,你的例子对我有用:

groovy -cp opencsv-2.2/deploy/opencsv-2.2.jar testg.groovy

#2


-1  

import au.com.bytecode.opencsv.*

The import is working fine for me

导入对我来说很好