我试图显示MS Access数据库的数据,我使用的是jacess库,但我得到了一个依赖错误,我不知道如何解决。下面是我的代码和错误:
import com.healthmarketscience.jackcess.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import java.nio.*;
import java.lang.*;
import org.apache.commons.*;
import org.apache.commons.lang3.builder.*;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
class Main {
private static Logger log=Logger.getLogger(Main.class);
public static void main(String args[]) {
DOMConfigurator.configure("lib\log4j.xml");
try {
Database d = Database.open(new File("lib\ExTables.mdb"));
System.out.println(d.getTable("Cliente").display());
} catch(Exception e) {
e.printStackTrace();
}
}
}
这是我的错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/builder/CompareToBuilder
at com.healthmarketscience.jackcess.RowId.compareTo(RowId.java:108)
at com.healthmarketscience.jackcess.IndexData$Entry.compareTo(IndexData.java:1825)
at com.healthmarketscience.jackcess.IndexData$Entry.compareTo(IndexData.java:1637)
at java.util.Collections.indexedBinarySearch(Unknown Source)
at java.util.Collections.binarySearch(Unknown Source)
at com.healthmarketscience.jackcess.IndexData$DataPage.findEntry(IndexData.java:2347)
at com.healthmarketscience.jackcess.IndexData.findEntryPosition(IndexData.java:709)
at com.healthmarketscience.jackcess.IndexData.access$3100(IndexData.java:54)
at com.healthmarketscience.jackcess.IndexData$EntryCursor.updatePosition(IndexData.java:2118)
at com.healthmarketscience.jackcess.IndexData$EntryCursor.restorePosition(IndexData.java:2057)
at com.healthmarketscience.jackcess.IndexData$EntryCursor.restorePosition(IndexData.java:2040)
at com.healthmarketscience.jackcess.IndexData$EntryCursor.beforeEntry(IndexData.java:2002)
at com.healthmarketscience.jackcess.IndexCursor.findPotentialRow(IndexCursor.java:439)
at com.healthmarketscience.jackcess.IndexCursor.findRowByEntryImpl(IndexCursor.java:342)
at com.healthmarketscience.jackcess.IndexCursor.findRowByEntry(IndexCursor.java:175)
at com.healthmarketscience.jackcess.Database$DefaultTableFinder.findRow(Database.java:2239)
at com.healthmarketscience.jackcess.Database$TableFinder.findObjectId(Database.java:2168)
at com.healthmarketscience.jackcess.Database.readSystemCatalog(Database.java:1081)
at com.healthmarketscience.jackcess.Database.<init>(Database.java:765)
at com.healthmarketscience.jackcess.Database.open(Database.java:589)
at com.healthmarketscience.jackcess.Database.open(Database.java:535)
at com.healthmarketscience.jackcess.Database.open(Database.java:510)
at com.healthmarketscience.jackcess.Database.open(Database.java:488)
at com.healthmarketscience.jackcess.Database.open(Database.java:467)
at Main.main(Main.java:19)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.builder.CompareToBuilder
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 25 more
这是我的命令行:
C:ProgrammiJavajre6binjavaw.exe -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:3280 -Dfile.encoding=Cp1252 -classpath "C:Documents and SettingslinosaDocumentiprogrammazioneworkspace_javaMSAccessbin;C:Documents and SettingslinosaDocumentiprogrammazioneworkspace_javaMSAccesslibjackcess-1.2.5.jar;C:Documents and SettingslinosaDocumentiprogrammazioneworkspace_javaMSAccessliblog4j-1.2.16.jar;C:Documents and SettingslinosaDocumentiprogrammazioneworkspace_javaMSAccesslibcommons-logging-1.1.1.jar;C:Documents and SettingslinosaDocumentiprogrammazioneworkspace_javaMSAccesslibjunit-4.10.jar;C:Documents and SettingslinosaDocumentiprogrammazionecommons-lang3-3.1-bincommons-lang3-3.1commons-lang3-3.1-tests.jar;C:Documents and SettingslinosaDocumentiprogrammazionecommons-lang3-3.1-bincommons-lang3-3.1commons-lang3-3.1.jar;C:Documents and SettingslinosaDocumentiprogrammazionecommons-lang3-3.1-bincommons-lang3-3.1commons-lang3-3.1-javadoc.jar;C:Documents and SettingslinosaDocumentiprogrammazionecommons-lang3-3.1-bincommons-lang3-3.1commons-lang3-3.1-sources.jar" Main
Commons Lang 3不向后兼容2.x。你必须下载2.6.
您可能还想研究Maven或Ant+Ivy,以使这种依赖解析更容易一些。
找到了;-)commons lang在类路径中,但它似乎是错误的版本。请求的包是org.apache.commons.lang.builder,它对commons-lang 2有效。在commons-lang3中,包是'org.apache.commons.lang3.builder'。因此,您必须包含一个公共语言2。x