• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

confusion about classpath and packages

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am confused about classpaths, packages, and directory structure. I had a program that was running, but when I made some changes to the directory structure, it stopped running. Here's what i have:

1.a directory (myclasses) with several graphing utilities I wrote a while back. Inside this directory there are the paths source\com\rephunk (where the java files are) and classes\com\rephunk. Each java file starts with �package com.rephunk�.
2.a project directory (punnett) with the same paths. In source\com\rephunk, there are two java files, one of which has the main procedure, called PunnettGui.java. These files also start with the same package statement.
3.I compile from the source folder of the project directory, using javac �cp .;c:\java\myclasses\classes;c:\java\punnett\classes �d ..\classes *.java This seems to work OK.
4.I try to run from the classes folder of the project directory, using java �cp .;c:\java\myclasses\classes com.rephunk.PunnettGui, and I get the NoClassDefFound error on the class PunnettGui. (I�ve also tried with java �cp .;c:\java\myclasses\classes;c:\java\punnett\classes com.rephunk.PunnettGui).

I would really appreciate any help!! Thank you,
-Karen.
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NoClassDefFound is actually different from ClassNotFound -- and is one of the most unhelpful and confusing errors out there.

Usually when you receive a NoClassDefFound, it can find the class that it's looking for. However, it cannot find a dependant class. But it won't tell you which dependant class it can't find. It jsut tells you that there's a problem with the main class.

Make sure that the classpath contains all dependant classes, and try again.
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could try adding -verbose switch on the java command line. It will show which classes the JVM is loading. Might help isolate the problem class.
It creates a long load list so you may want to redirect the output to a file and use an editor to search for your directory path/files.
ex: java -verbose ... > output.txt
 
Karen Nelson
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the help! Problem solved.

For the record, I looked in the classes directory and found that some of my classfiles were ending up in the wrong directory, because I had neglected to put a package statement in one file.

In addition I had left a slash out of the classpath name in the java statement. Either one was enough to scuttle the program!

Thank you again!!!
-Karen.
[ November 04, 2005: Message edited by: Karen Nelson ]
 
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic