java - Jackcess "NoClassDefFoundError"异常

标签 java ms-access netbeans-7 jackcess

我正在使用 jackcess 连接到我的 Access 数据库。但我正在关注异常

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,但它也不起作用。如何解决我的问题?

最佳答案

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

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

C:\Users\Public\Java\

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

C:\Users\Public\Java\commons-lang-2.6\
C:\Users\Public\Java\commons-logging-1.1.3\

我启动了 NetBeans 并创建了一个名为“myJackcessTest”的新项目(用于 Java 应用程序)。我在 TreeView 中展开项目,右键单击“库”,选择“添加 JAR/文件夹...”,然后添加三个 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)

关于java - Jackcess "NoClassDefFoundError"异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19450755/

相关文章:

java - 对象池、IoC 和工厂 : When and Where?

java - 实现 toString() 时使用反射有意义吗?

java - Guice MethodInterceptor 应该返回什么

sql - 使用 SQL 在查询中引用表单上的字段

ms-access - 如何获取组合框中未绑定(bind)列的值?

java - 无法在 Netbeans 7.2 IDE 上运行 Play Framework 项目

java - Glassfish 部署错误,并包含无信息的错误消息

java - hibernate 获取模式加入不工作

arrays - UDF 返回的数组对于调用范围而言太大或太小

java - 解析树中节点的深度