• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NoClassDefFoundError... but program compiles fine

 
Christopher Young
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Chiranjeevi Kanthraj
Ranch Hand
Posts: 290
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try like this

javac pacakage.Class.java
java -cp . pakasge.Class
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Christopher Young
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
none of them are packages, though.
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java -cp Source;Structures;ships MyClass then?
 
Christopher Young
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah.

Ah!

Thank you, man.

That works.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rodrigo Tomita
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic