英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论