File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes NoClassDefFoundError... but program compiles fine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NoClassDefFoundError... but program compiles fine" Watch "NoClassDefFoundError... but program compiles fine" New topic
Author

NoClassDefFoundError... but program compiles fine

Christopher Young
Ranch Hand

Joined: Nov 02, 2007
Posts: 63
Ok. Well, I have a program that is organized into a set of folders. One is called "Source", another one is called "Structures", and another one is called "ships".

These three folders are all in the same folder that has the name of the thing I'm working on. The driver class is in "Source"

Using javac on all the files works fine, but when I try to run the program I get a NoClassDefFoundError for a class that is in the folder "Structures".

This worked fine with an IDE so I have no idea what I am doing wrong (And I'm wanting to learn how this all works from the commandline before I find another IDE).

How do I remedy this?

Sorry if this sounds a little vague. I can elaborate more if needed.


Technology can never substitute for knowledge.
Chiranjeevi Kanthraj
Ranch Hand

Joined: Feb 18, 2008
Posts: 290

try like this

javac pacakage.Class.java
java -cp . pakasge.Class


-Chiru
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

Originally posted by Chiru Raj:
try like this

javac pacakage.Class.java
java -cp . pakasge.Class

javac takes regular paths, so it would be

[ June 08, 2008: Message edited by: Rob Prime ]

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Christopher Young
Ranch Hand

Joined: Nov 02, 2007
Posts: 63
none of them are packages, though.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

java -cp Source;Structures;ships MyClass then?
Christopher Young
Ranch Hand

Joined: Nov 02, 2007
Posts: 63
Ah.

Ah!

Thank you, man.

That works.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Christopher Young:
... This worked fine with an IDE so I have no idea what I am doing wrong (And I'm wanting to learn how this all works from the commandline before I find another IDE)...

Yeah, this is one reason IDEs are a bad idea until you know how it really works. I'm glad you're taking the time to work it out without an IDE. More importantly, you will be glad you did.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Rodrigo Tomita
Ranch Hand

Joined: Apr 28, 2008
Posts: 70
Christopher,

Just adding a small something here... although you have it working, you may want to read more about "classpath" and how it works for classes and packages. It can also be an environment variable (although you will read in this forum that usually using the -cp argument is better).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NoClassDefFoundError... but program compiles fine