Jackcess“NoClassDefFoundError”异常

时间:2013-10-18 13:20:59

标签: java ms-access netbeans-7 jackcess

我使用jackcess与我的访问数据库保持一致。但我正在追踪异常

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/builder/CompareToBuilder
    at com.healthmarketscience.jackcess.impl.RowIdImpl.compareTo(RowIdImpl.java:113)
    at com.healthmarketscience.jackcess.impl.IndexData$Entry.compareTo(IndexData.java:1838)
    at com.healthmarketscience.jackcess.impl.IndexData$Entry.compareTo(IndexData.java:1646)
    at java.util.Collections.indexedBinarySearch(Collections.java:273)
    at java.util.Collections.binarySearch(Collections.java:259)
    at com.healthmarketscience.jackcess.impl.IndexData$DataPage.findEntry(IndexData.java:2368)
    at com.healthmarketscience.jackcess.impl.IndexData.findEntryPosition(IndexData.java:722)
    at com.healthmarketscience.jackcess.impl.IndexData.access$3300(IndexData.java:56)
    at com.healthmarketscience.jackcess.impl.IndexData$EntryCursor.updatePosition(IndexData.java:2133)
    at com.healthmarketscience.jackcess.impl.IndexData$EntryCursor.restorePosition(IndexData.java:2072)
    at com.healthmarketscience.jackcess.impl.IndexData$EntryCursor.restorePosition(IndexData.java:2055)
    at com.healthmarketscience.jackcess.impl.IndexData$EntryCursor.beforeEntry(IndexData.java:2017)
    at com.healthmarketscience.jackcess.impl.IndexCursorImpl.findPotentialRow(IndexCursorImpl.java:368)
    at com.healthmarketscience.jackcess.impl.IndexCursorImpl.findFirstRowByEntryImpl(IndexCursorImpl.java:262)
    at com.healthmarketscience.jackcess.impl.IndexCursorImpl.findFirstRowByEntry(IndexCursorImpl.java:135)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl$DefaultTableFinder.findRow(DatabaseImpl.java:1890)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl$TableFinder.findObjectId(DatabaseImpl.java:1799)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl.readSystemCatalog(DatabaseImpl.java:804)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl.<init>(DatabaseImpl.java:513)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl.open(DatabaseImpl.java:386)
    at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:170)
    at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:193)
    at ass.Access.main(Access.java:25)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.builder.CompareToBuilder
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 23 more

我使用过jdbc,但它也没用。怎么能解决我的问题?

2 个答案:

答案 0 :(得分:5)

以下是我如何让Jackcess工作,从Windows 8上全新安装的NetBeans 7.4开始:

我通过“寻找最新版本?”下载了最新的Jackcess JAR文件。 files页面上的链接。我把它保存在文件夹

C:\用户\公共\爪哇\

如Jackcess的Project Dependencies页面所列,我下载了两个必需依赖项的ZIPped二进制文件:commons-lang v2.x和commons-logging v1.x.我将ZIP文件解压缩到上面的文件夹中,因此它现在包含两个子文件夹

C:\用户\公共\爪哇\公地琅-2.6 \
C:\用户\公共\爪哇\共享记录-1.1.3 \

我启动了NetBeans并创建了一个名为“myJackcessTest”的新项目(用于Java应用程序)。我在树视图中展开了Project,右键单击“Libraries”,选择“Add JAR / Folder ...”,并添加了三个JAR文件:

Libraries.png

一旦完成,我就创建了我的小测试应用程序......

package myjackcesstest;

import com.healthmarketscience.jackcess.*;
import java.io.File;
import java.io.IOException;

public class MyJackcessTest {

    public static void main(String[] args) {
        try {
            Table table = DatabaseBuilder.open(new File("C:\\Users\\Public\\Database1.accdb")).getTable("Clients");
            System.out.println(String.format("table contains %d row(s)", table.getRowCount()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

...当我点击 F6 时,它运行良好:

run:
table contains 1 row(s)
BUILD SUCCESSFUL (total time: 0 seconds)

答案 1 :(得分:3)

Jackcess在dependency上有一个Jakarta Commons Lang。您需要确保公共语言和其他依赖项都在类路径上。