![](/img/trans.png)
[英]Dynamically load jar file in groovy file, failed XML Parsing Error
[英]Import error in jar file in Groovy
與此問題類似,我有一個小的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...");
}
我一直收到錯誤“無法解析類au.com.bytecode.opencsv.CSVReader”。 我什至將opencsv jar文件放在與腳本相同的目錄中,但無法識別。 我以為這是一個類路徑問題,所以我嘗試使用-cp標記僅收到相同的錯誤。
我從命令行作為$ groovy testg.groovy
Groovy不會自動從當前工作目錄中拾取jar。 您可以使用類路徑( -cp <classpath>
)調用groovy,也可以將jar文件${user.home}/.groovy/lib
放入。
當我啟動它時,您的示例對我有用:
groovy -cp opencsv-2.2/deploy/opencsv-2.2.jar testg.groovy
import au.com.bytecode.opencsv.*
導入對我來說很好
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.