0

I am a beginner java developer using Eclipse. I want to read in a CSV file and want to use opencsv utilities as a reader (and use other opencsv utilities when I get off the ground). I have downloaded the JAR (ver 5.8) and added it to my Build Configuration. I have addressed all compiler errors, but at runtime, I am getting a ClassNotFoundException for com.opencsv.bean.CsvToBeanBuilder. I have tried a previous opencsv version (5.7.1) but get the same results. I can see the com.opencsv.bean.CsvToBeanBuilder.class when I hunt through the files. Must be something simple I am missing? I have downloaded the JAR file only, no source or javadoc.

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

import com.opencsv.bean.CsvToBeanBuilder;


public class RaceResultsParser_v2 {

    public static void main(String[] args) {

        String inputfile = "inputfile.csv";
    
        try {
            List<ClubMembers> memberlist_input = new CsvToBeanBuilder<ClubMembers>(new FileReader(inputfile)).withType(ClubMembers.class).build().parse();
        } catch (FileNotFoundException e) {

            System.out.println("An exception occurred while opening the CSV file [" + inputfile + "]: " + e.getMessage());
            System.out.println("File Not Found Exception");
            e.printStackTrace();
            return;
        }

Project Explorer

I have trolled stack overflow and the internet more broadly but can't seem to find my solution.

Console output from the program run:

Exception in thread "main" java.lang.NoClassDefFoundError: com/opencsv/bean/CsvToBeanBuilder
    at RaceResultsParser_v2.main(RaceResultsParser_v2.java:17)
Caused by: java.lang.ClassNotFoundException: com.opencsv.bean.CsvToBeanBuilder
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    ... 1 more

When I add opencsv to the Run Configuration, a slightly different console error comes up referencing org.apache.commons.collections4.MultiValueMap:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections4/MultiValuedMap
    at RaceResultsParser_v2.main(RaceResultsParser_v2.java:18)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections4.MultiValuedMap
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    ... 1 more

Run Configuration

4
  • Did you check the Run configuration within Eclipse and make sure the opencsv file is appearing in the classpath? You should check under User Entries on the Classpath tab of the Java Application tun configuration. Feel free to add an attachment of the run configuration for review. Commented Oct 2, 2023 at 19:14
  • I added opencsv to the Run configuration and come up with a slightly different ClassNotFoundException error for org.apache.commons.collections4.MultiValuedMap. I will post the run configuration Commented Oct 2, 2023 at 19:45
  • You're missing a dependency of commons collections4 too Commented Oct 2, 2023 at 20:15
  • Thank you for your help, I think I am up and running and on to working on the usage and debugging. The initial resolution was to add the JAR dependencies to the Run Configuration as well as the Build Configuration. Which then led to the discovery of other dependencies to Apache JAR libraries. Commented Oct 2, 2023 at 21:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.