Jackcess “NoClassDefFoundError” exception

安稳与你 提交于 2019-11-28 12:48:58

Jackcess has a dependency on Jakarta Commons Lang. You need to make sure that the commons lang and the other dependencies are on your classpath.

Here's how I got Jackcess working, starting with a fresh install of NetBeans 7.4 on Windows 8:

I downloaded the latest Jackcess JAR file via the "Looking for the latest version?" link on files page. I saved it in the folder

C:\Users\Public\Java\

As listed on the Project Dependencies page for Jackcess, I downloaded the ZIPped binaries for the two required dependencies: commons-lang v2.x, and commons-logging v1.x. I unpacked the ZIP files into the above folder, so it now contained two sub-folders

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

I launched NetBeans and created a new Project (for a Java Application) named "myJackcessTest". I expanded the Project in the tree view, right-clicked "Libraries", chose "Add JAR/Folder...", and added the three JAR files:

Once that was done, I created my little test app...

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();
        }
    }
}

...and when I hit F6 it ran fine:

run:
table contains 1 row(s)
BUILD SUCCESSFUL (total time: 0 seconds)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!