1

I found that I cannot just run import com.opencsv.CSVReader; statement in my JDK framework.

Edited1: I was asked to make it clearer:

import com.opencsv.CSVReader;

throws

The import com.opencsv cannot be resolved

(using VSCode)

How can I add OpenCSV to my framework?

This question arose from import csv to JTable

Edited2: It is now clear that AdoptOpenJDK is not the issue and that the question is independent from the jdk framework and version. Thus I changed the question (and respective tags) from

OpenCSV - CSVReader alternative in AdoptOpenJDK

to

How to implement OpenCSV - CSVReader in a JDK

11
  • 1
    Is the jar visible on the classpath? Commented Jun 22, 2020 at 9:08
  • 1
    Please expand on "does not seem to support". What is the problem that you see? Commented Jun 22, 2020 at 9:11
  • 1
    Make sure you have added the OpenCSV JAR file to VS Code first, regardless of what version of Java you are using (Oracle's or others). See here. If you don't have the JAR for OpenCSV, you can download the latest version from Maven here. Commented Jun 22, 2020 at 12:17
  • 1
    @Lorenz We have all been there. The classpath is one of the hard things to learn with Java, so you just have cleared the first hurdle towards mastery. Now go study :) Commented Jun 24, 2020 at 13:23
  • 1
    I am glad you solved your problem - that's great. If I wrote an answer, it would effectively be a duplicate of the answer(s) in the other question I linked to. This site works hard to discourage duplicate questions and answers. And don't worry about the supposed badness of your question - sometimes (often?) we don't know what we don't know. You improved the question - which is exactly the right thing to have done. Commented Jun 24, 2020 at 13:35

1 Answer 1

2

Make sure you have added the OpenCSV JAR file to VS Code first, regardless of what version of Java you are using (Oracle's or others). See details in the answers to this question for related information.

If you don't have the JAR for OpenCSV, you can download the latest version from Maven here. Maven also lets you search for JARs by names/keywords - see here.

In case you are not familiar with Maven (or Gradle): A next logical step (if you are going to be doing any amount of Java work) might be to consider using a more fully-featured Java IDE (e.g. Eclipse, NetBeans) and look at how those tools handle JARs via their Maven (or Gradle) project types. Instead of downloading individual JARs, you would add entries to the auto-created "pom.xml" file used by each of your Java projects. So, for OpenCSV, you would add this:

<dependency>
    <groupId>com.opencsv</groupId>
    <artifactId>opencsv</artifactId>
    <version>5.2</version>
</dependency>

The huge advantage of this is that it automatically downloads any transitive dependencies into your project - i.e. any additional JAR files which may be needed by the JAR file that you need to use.

Sign up to request clarification or add additional context in comments.

Comments

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.