3

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
jtahlborn
  • 52,909
  • 5
  • 76
  • 118
haltman
  • 553
  • 1
  • 12
  • 24
  • Do you have all the required jars in your classpath? CompareToBuilder belongs to commons-lang. – Andreas Dec 13 '11 at 10:59
  • Thanks for answering Andreas! I'm not sure about it! Is commons-lang inside apache library? – haltman Dec 13 '11 at 11:14
  • Apache has lot's of projects which releases libraries. The library which contains your class has the name commons-lang- – Andreas Dec 13 '11 at 11:49
  • Excuse me how can I extract it? I've imported latest one commons-lang3-3.1.jar – haltman Dec 13 '11 at 12:11
  • 1
    It depends on the method how you start your application. If you start it from the commandline you could send me the commandline (something like java -cp xx.jar.. MyStartClass). If you start it from an IDE the IDE generates a commandline and starts the program. In Eclipse you get the commandline when you go to the debug-view and do a right-click on the running process. Choose properties and you see the whole commandline with the effective classpath. Do you use eclipse? – Andreas Dec 13 '11 at 12:53
  • yes I use eclipse I attach in mainanswer my command line – haltman Dec 13 '11 at 13:23

2 Answers2

8

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.

artbristol
  • 32,010
  • 5
  • 70
  • 103
  • Thanks artbristol! Downgrade library resolve my dependence problem but I get a nullpointerexception, I've to study why...LOL – haltman Dec 13 '11 at 14:01
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

Andreas
  • 1,183
  • 1
  • 11
  • 24