从jar文件运行类的java
我的代码如下:
import java.io.File;
import java.io.FileReader;
import java.io.FileOutputStream;
import com.opencsv.CSVReader;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import java.util.Scanner;
public class CreateDocument
{
public static void main(String[] args)throws Exception
{
CSVReader reader = new CSVReader(new FileReader("invoicedetails.csv"));
String [] nextLine;
while ((nextLine = reader.readNext()) != null) {
// nextLine[] is an array of values from the line
System.out.println(nextLine[0] + nextLine[1] + nextLine[2]);
}
}
}
# 1 楼答案
jar文件只包含在IDE项目中编写的类。您需要在java命令中指定包含所有依赖项的类路径
java-classpath=“PATH_TO_OPENCSV”-jar InvoiceBuilder。罐子
# 2 楼答案
正如其他人指出的那样,您缺少所创建的jar中的依赖项。你可以在Idea中创建一个“胖”罐子。见this blog post。这篇文章很旧,但也应该适用于新版本