• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

Jackcess; CLASSPATH? Jar? What?! I just don't get it! (java.lang.NoClassDefFoundError)

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just started with java last week and have been reading the book called "Head First Java", it's pretty good for someone like me. Java was pretty easy... till today. I wanted to see if I could connect to Access using Jackcess. Then all these stupid and supposedly redundant question hits me... where do I put the jar-file?! Do I have to change my paths... and mend my ways?

It doesn't say anything about it in the book. Jackcess isn't mentioned specifically in the book, but my point is - it doesn't specifically say what to do with all those interesting libraries you find at sourceforge.net... as a n00b... I've copied the jar to various locations, but the thing still won't run.

My source files (my experiments so far... or more precise... my code-excrements, haha... but not for long, hopefully) are all in C:\Java. The jar file is there too. It's even unpacked under C:\Java\com ... it's... EVERYWHERE!!

The code compiles without error, but it won't run and gives the error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at com.healthmarketscience.jackcess.Database.<clinit><Database.java:84>
at Tester.main<Tester.java:10>
...


I went to http://jackcess.sourceforge.net/ and tried running a code from that page as an example (it's the one further down)... it compiles, but still gives the same error.

My path is:
C:\Programs\Java\jdk1.6.0_21\bin;C:\Java;C:\Java\jackcess-1.2.0.jar

My classpath is:
.;C:\Programs\Java\jre6\lib\ext\QTJava.zip;C:\Java;C:\Programs\Java\jdk1.6.0_21\lib\jackcess-1.2.0.jar;C:\Java\jackcess-1.2.0.jar

I use EditPlus as an editor, as I want to know how things run before I jump into NetBeans or Eclipse.


The code
------------
import com.healthmarketscience.jackcess.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import java.nio.*;

class Tester {
public static void main(String args[]) {
try {
Database db = Database.create(new File("new.mdb")); // this is line nr 10
Table newTable = new TableBuilder("NewTable")
.addColumn(new ColumnBuilder("a")
.setSQLType(Types.INTEGER)
.toColumn())
.addColumn(new ColumnBuilder("b")
.setSQLType(Types.VARCHAR)
.toColumn())
.toTable(db);
newTable.addRow(1, "foo");

catch(Exception e)
{
e.printStackTrace();
}
}
}
------------

So what is it... is it the Classpath that I simply don't understand... do I have to install everything once more or... should I take up on knitting instead...?
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know nothing about jackcess but you could be missing a jar in your classpath called commons-logging.jar I suggest you check the jackcess documentation to work out why you are missing this and perhaps other jar's

Regards
TY
 
Orgar Steinblokkur
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Thomas, that did help me get past that obstacle!

I happily downloaded the 'commons.logging' and ran into another missing 'common.lang'... no matter.

The only thing that seems to be working for me, is using C:\Java as a repository for the code and all unzipped jar-files. This can't be "optimum". The book says, that it's possible to import the libraries from jar-files without unzipping them. So how do I go on about this?

And one more thing, why do most beginner examples include "foo"? Like print or write "foo". Is this a Java-community-thing?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no need to unzip (or unjar) any of the jar files; just add them correctly to the CLASSPATH, not the PATH. In light of that, this doesn't make sense:

My path is:
C:\Programs\Java\jdk1.6.0_21\bin;C:\Java;C:\Java\jackcess-1.2.0.jar


The PATH is for executables, not for Java classes or libraries.

Nor does this:

My classpath is:
.;C:\Programs\Java\jre6\lib\ext\QTJava.zip;C:\Java;C:\Programs\Java\jdk1.6.0_21\lib\jackcess-1.2.0.jar;C:\Java\jackcess-1.2.0.jar


Adding a directory only makes sense if it contains loose class files, and adding a library twice is a problem waiting to happen.

Overall, I strongly recommend NOT to use the CLASSPATH environment variable - it causes more problems than it solves. Use the "-cp" switch for javac and java instead.
 
Orgar Steinblokkur
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help, guys!

Nothing worked, and after changing my paths several times, copying jars hither and dither... I thought of the simple solution of just putting everything as it was supposed to be logically (just like Ulf suggested, really) and then re-boot the machine... it worked!

The problem was probably due to some of the system variables being locked or in use. I read somewhere, that re-booting isn't necessary on XP Pro so I disregarded it at first... guess I shouldn't believe everything I read.
reply
    Bookmark Topic Watch Topic
  • New Topic