com.opencsv在从控制台启动时找不到

huangapple go评论65阅读模式
英文:

com.opencsv not found when lauched from console

问题

我有一个Maven项目,简单地读取一个CSV文件并将数据写入另一个文件。当我从IntelliJ构建/运行时,它运行良好,但当我从控制台运行$ java read.java时,它会产生以下错误:

src/main/java/read.java:1: error: package com.opencsv does not exist
import com.opencsv.CSVReader;

对于CSVWriter也是同样的情况。
我已经将.jar文件添加到了我的项目中,但并不成功。我如何能够从控制台启动我的应用(这样我就可以在启动时使用参数)?

谢谢

英文:

I have a Maven project that simply reads a CSV file and writes data to another file. When building/running from IntelliJ, it works fine but when I run $ java read.java from the console, it gives

src/main/java/read.java:1: error: package com.opencsv does not exist
import com.opencsv.CSVReader;

Same thing for CSVWriter.
I added the .jar to my project but it was not successful. How can I launch my app from console (so I can use arguments as I launch it)?

Thank you

答案1

得分: 1

你只需要将必要的 JAR 包添加到类路径中。

例如:

java -cp libs/opencsv-5.2.jar read.java

参考:

https://docs.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html

英文:

You just need to add the neccesary jars to the classpath.

For example:

java -cp libs/opencsv-5.2.jar read.java

See:

https://docs.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html

huangapple
  • 本文由 发表于 2020年10月17日 07:35:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/64397690.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定