NoClassDefFoundError after adding Opencsv jar to project

女生的网名这么多〃 提交于 2019-12-11 03:16:39

问题


I've added the open csv jar to my project to enable data to be written out to file in csv format.

The jar file was added using the following steps:

1.Properties --> Add external jars --> opencsv-3.1.jar
2.Order & Eport tab --> tick, opencsv-3.1.jar

But when I run the project I get an error stating that one of the methods belonging to the opencsv jar cannot be found: java.lang.NoClassDefFoundError: com.opencsv.CSVWriter

Does anyone know how to resolve this error or am I missing some step in adding the jar to the project?

`


回答1:


See javadoc of API

CSVWriter is in au.com.bytecode.opencsv package




回答2:


As cross-listed from here, this was my solution to the problem:

I have been struggling with getting OpenCSV set up with Maven and eclipse for a while due to exactly the same error. Ultimately I abandoned OpenCSV and used CSVParser instead, which is available from the Apache Commons and works much more readily.

Update your POM with the dependency listed here, and the following will work out-of-the-box:

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;

import java.io.FileReader;
import java.io.Reader;

public class importFile {
    public static void main(String[] args) {
        Reader in = new FileReader( csvFileInput );
        CSVParser parser = new CSVParser( in, CSVFormat.DEFAULT );
        List<CSVRecord> list = parser.getRecords();

        for( CSVRecord row : list )
            for( String entry : row )
                System.out.println( entry );
    }
}


来源:https://stackoverflow.com/questions/27770584/noclassdeffounderror-after-adding-opencsv-jar-to-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!