问题
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
回答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 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.
来源:https://stackoverflow.com/questions/62510811/how-to-implement-opencsv-csvreader-in-a-jdk-i-am-using-vscode