How do a I resolve a java jackcess dependence erro

2019-05-14 05:47发布

问题:

I'm tring to dispaly data from an MS Access db, I'm useing Jackcess library but I get a dependence error that I do not how to resolve. Here is my code and error:

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

Here is my error:

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

That's my command line:

 C:\Programmi\Java\jre6\bin\javaw.exe -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:3280 -Dfile.encoding=Cp1252 -classpath "C:\Documents and Settings\linosa\Documenti\programmazione\workspace_java\MSAccess\bin;C:\Documents and Settings\linosa\Documenti\programmazione\workspace_java\MSAccess\lib\jackcess-1.2.5.jar;C:\Documents and Settings\linosa\Documenti\programmazione\workspace_java\MSAccess\lib\log4j-1.2.16.jar;C:\Documents and Settings\linosa\Documenti\programmazione\workspace_java\MSAccess\lib\commons-logging-1.1.1.jar;C:\Documents and Settings\linosa\Documenti\programmazione\workspace_java\MSAccess\lib\junit-4.10.jar;C:\Documents and Settings\linosa\Documenti\programmazione\commons-lang3-3.1-bin\commons-lang3-3.1\commons-lang3-3.1-tests.jar;C:\Documents and Settings\linosa\Documenti\programmazione\commons-lang3-3.1-bin\commons-lang3-3.1\commons-lang3-3.1.jar;C:\Documents and Settings\linosa\Documenti\programmazione\commons-lang3-3.1-bin\commons-lang3-3.1\commons-lang3-3.1-javadoc.jar;C:\Documents and Settings\linosa\Documenti\programmazione\commons-lang3-3.1-bin\commons-lang3-3.1\commons-lang3-3.1-sources.jar" Main

回答1:

Commons Lang 3 is not backward compatible with 2.x. You'll have to download 2.6.

You might also want to investigate Maven or Ant+Ivy to make this kind of dependency resolution a bit easier.



回答2:

Found it ;-) The commons lang is in the classpath, but it seems to be the wrong version. The requested package is org.apache.commons.lang.builder, which is valid for commons-lang 2.x in commons-lang3 the package is 'org.apache.commons.lang3.builder'. So you have to include a commons-lang 2.x