Menu

Problem running Jackcess to access an Access database

Help
2015-09-06
2015-09-08
  • Paul S Poole

    Paul S Poole - 2015-09-06

    *** Problem running Jackcess to access an Access database

    I am having a problem getting Jackcess working. I have tried to follow the exact steps described by Gord Thompson on his post here:

    http://stackoverflow.com/questions/19450755/jackcess-exception?rq=1

    Note that his post was nearly two years ago.
    I am well aware that two years is a lifetime in the software world, so there is no telling what may have changed between then and now re requirements for running Jackcess.

    Gord's Jackcess test program ran, but I am getting a NoClassDefFoundError error trying to run the same code (in NetBeans):

    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

    Here's is what I have done, trying to exactly follow the steps in Gord's post.

    I just installed NetBeans 8.0 on Windows 7 (64 bit).

    Then downloaded the latest Jackcess JAR file, jackcess-2.1.2.jar, and saved it in 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, and commons-logging. I unpacked the ZIP files into the above folder, so it now contains two sub-folders:
    C:\Users\Public\Java\commons-lang3-3.4\ C:\Users\Public\Java\commons-logging-1.2\

    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:

    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 used Gord's java code (thanks!) to create a test app in NetBeans (thanks, Gord):

    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(table.getRowCount());
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("Done.");
    }
    

    }

    In his case, the program ran, returning the number of rows in his access db table.
    But in my case, I get the following runtime error in NetBeans:

    run:
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at com.healthmarketscience.jackcess.impl.DatabaseImpl.<clinit>(DatabaseImpl.java:82)
    at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:248)
    at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:287)
    at myjackcesstest.MyJackcessTest.main(MyJackcessTest.java:11)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 4 more
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)

    Am I missing an apache jar or some other jar(s) that Jackcess needs? Or is it something else?
    Any help much appreciated. Please advise!

    Regards, Paul Poole aka CCapTN: CCapTN@gmail.com

     
    • Gord Thompson

      Gord Thompson - 2015-09-06

      Try using "commons-logging-1.1.1.jar" from the lib\ folder of the UCanAccess distribution and see if that helps. Also, you are trying to use commons-lang 3.x but Jackcess requires commons-lang 2.x.

       

      Last edit: Gord Thompson 2015-09-06
  • Paul S Poole

    Paul S Poole - 2015-09-06

    Gord, thanks! I know that you are spending some of your weekend time trying to help people!
    Much appreciated, Kemo Sabe! (Kemo Sabe is what Tonto called the Lone Ranger, meaning failthful friend!)

    Ok, I replaced those two jars in the NetBeans Libraries for the myjackcess test project.
    So I now have these jars:
    commons-logging-1.1.1.jar
    commons-lang-2.6.jar
    jackess-2.1.2.jar

    Trying a run, i get the following. Java JRE seems much less angry than before, but we are still not there! Any other thing I should try next? What is the "org/apache/commons/logging/LogFactory" that it is fussing about?

    run:
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at com.healthmarketscience.jackcess.impl.DatabaseImpl.<clinit>(DatabaseImpl.java:82)
    at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:248)
    at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:287)
    at myjackcesstest.MyJackcessTest.main(MyJackcessTest.java:11)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 4 more
    Java Result: 1
    BUILD SUCCESSFUL (total time: 1 second)

    By the way, Gord, you often have images in your SourceForge posts. How do you do that? I clicked on the image symbol that shows when you are posting, and it pops up this: "" but I don't know what to do after that. For example, using irfanview, I took a snapshot of a cropped portion of the NetBeans screen showing the libraries for the myjackcess project, to show the jars. I saved that image to a .jpg file. Is there a way to put that image in my SF post???

    Thanks!

     
    • Gord Thompson

      Gord Thompson - 2015-09-08

      Re: error - See if you have a CLASSPATH environment variable defined at the OS level, and, if so, whether it contains a reference to another version of commons-logging. Strange things can happen if Java sees more than one reference to a particular library.

      Re: images - You need to upload the image to a place on the Internet where it can be retrieved via an HTTP URL. Then you include a link to the image in your post, e.g.,

      ![image text](http://example.com/screenshot.png)
      
       

Log in to post a comment.