This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Jackcess; CLASSPATH? Jar? What?! I just don't get it! (java.lang.NoClassDefFoundError) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Jackcess; CLASSPATH? Jar? What?! I just don Watch "Jackcess; CLASSPATH? Jar? What?! I just don New topic
Author

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

Orgar Steinblokkur
Greenhorn

Joined: Jul 01, 2010
Posts: 3
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...?
Thomas Young
Greenhorn

Joined: Jul 17, 2008
Posts: 29
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

Joined: Jul 01, 2010
Posts: 3
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?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41068
    
  43
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.


Ping & DNS - my free Android networking tools app
Orgar Steinblokkur
Greenhorn

Joined: Jul 01, 2010
Posts: 3
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Jackcess; CLASSPATH? Jar? What?! I just don't get it! (java.lang.NoClassDefFoundError)
 
Similar Threads
Need help with my first JDBC program
Add JFXPanel in JApplet Java SE
Cannot figure out what I forgot to set, or I set wrong, or forgot to install?
[Agile Java - Langr, p127] Class not found "sis.AllTests"
No Class found error !!! please help