Java Jadex中的NoClassDefFoundError
我用的是jadex0.96。我想使用V2,但我无法使用当前版本在Mac上稳定地初始化JCC 使用Jadex 0.96,我尝试使用opencsv: 这需要我向项目中添加一个.jar文件。我构建了一些依赖于opencsv的类,这些类在普通Java中运行时运行良好。但是,当我尝试在Jadex计划中初始化其中一个类时,会出现以下错误(omni0是代理的名称,DataGrid是使用opencsv的类,DataMap是使用DataGrid的类):Java Jadex中的NoClassDefFoundError,java,Java,我用的是jadex0.96。我想使用V2,但我无法使用当前版本在Mac上稳定地初始化JCC 使用Jadex 0.96,我尝试使用opencsv: 这需要我向项目中添加一个.jar文件。我构建了一些依赖于opencsv的类,这些类在普通Java中运行时运行良好。但是,当我尝试在Jadex计划中初始化其中一个类时,会出现以下错误(omni0是代理的名称,DataGrid是使用opencsv的类,DataMap是使用DataGrid的类): 有什么想法吗?我刚写了自己的简单的CSVDataReade
有什么想法吗?我刚写了自己的简单的
CSVDataReader
类来代替CSVReader
。它同样适用于我的应用程序,并避免了由于引用jar而产生的Jadex错误
这是一门课程,以防任何人需要:
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class CSVDataReader {
private String filePath;
public CSVDataReader(String filePath) throws IOException {
this.filePath = filePath;
}
public List<String[]> readAll() throws IOException {
// Get Buffered Reader
FileInputStream fstream = new FileInputStream(filePath);
DataInputStream in = new DataInputStream(fstream);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
// Init lineList
List<String[]> lineList = new ArrayList<String[]>();
// Get Lines
String strLine;
while ((strLine = bufferedReader.readLine()) != null) {
String[] strings = strLine.split(",");
lineList.add(strings);
}
//Close the input stream
in.close();
return lineList;
}
public static void main(String [] args){
try {
String filePath = "test.csv";
CSVDataReader reader = new CSVDataReader(filePath);
List<String[]> lineList = reader.readAll();
for(String[] strings : lineList){
for (String s : strings) {
System.out.print(s+" ");
}
System.out.println();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
导入java.io.BufferedReader;
导入java.io.DataInputStream;
导入java.io.FileInputStream;
导入java.io.IOException;
导入java.io.InputStreamReader;
导入java.util.ArrayList;
导入java.util.List;
公共类CSVDataReader{
私有字符串文件路径;
公共CSVDataReader(字符串文件路径)引发IOException{
this.filePath=filePath;
}
public List readAll()引发IOException{
//获取缓冲读取器
FileInputStream fstream=新的FileInputStream(filePath);
DataInputStream in=新的DataInputStream(fstream);
BufferedReader BufferedReader=新的BufferedReader(新的InputStreamReader(in));
//初始化行列表
List lineList=new ArrayList();
//排队
弦斯特林;
而((strLine=bufferedReader.readLine())!=null){
String[]strings=strLine.split(“,”);
lineList.add(字符串);
}
//关闭输入流
in.close();
返回行列表;
}
公共静态void main(字符串[]args){
试一试{
字符串filePath=“test.csv”;
CSVDataReader=新的CSVDataReader(文件路径);
List lineList=reader.readAll();
对于(字符串[]字符串:行列表){
用于(字符串s:字符串){
系统输出打印(s+“”);
}
System.out.println();
}
}捕获(IOE异常){
e、 printStackTrace();
}
}
}
您是否尝试过从命令行运行它?例如:java-cp some.jar:opencsv-2.2.jar:bin YourMainClass
,只是为了验证找到了opencsv jar。我自己从来没有使用过系统属性:这可能是绝对/相对路径的问题吗?谢谢你的评论。不幸的是,我现在使用的Jadex版本(EJADE)与Eclipse紧密集成,因此从命令行运行它是不可行的。我现在正在使用opencsv的绝对路径,不知道在Jadex中运行的代理的相对路径应该是什么。即使我有相同的问题,我已经定义了opencsv
,但不知何故它没有被引用,是否有其他解决方案适合您?我最后也使用了这个解决方案。唯一的问题是单词周围是否有双引号(这是一个标准的csv文件)。
System.setProperty("java.class.path",currentPath+opencsvPath);
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class CSVDataReader {
private String filePath;
public CSVDataReader(String filePath) throws IOException {
this.filePath = filePath;
}
public List<String[]> readAll() throws IOException {
// Get Buffered Reader
FileInputStream fstream = new FileInputStream(filePath);
DataInputStream in = new DataInputStream(fstream);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
// Init lineList
List<String[]> lineList = new ArrayList<String[]>();
// Get Lines
String strLine;
while ((strLine = bufferedReader.readLine()) != null) {
String[] strings = strLine.split(",");
lineList.add(strings);
}
//Close the input stream
in.close();
return lineList;
}
public static void main(String [] args){
try {
String filePath = "test.csv";
CSVDataReader reader = new CSVDataReader(filePath);
List<String[]> lineList = reader.readAll();
for(String[] strings : lineList){
for (String s : strings) {
System.out.print(s+" ");
}
System.out.println();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}