File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Package woes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Package woes" Watch "Package woes" New topic

Package woes

Cathy Song
Ranch Hand

Joined: Jul 01, 2003
Posts: 92
I have 2 classes(A, B) in a package. -->lev1.lev2.lev3;

So, I created 3 directories lev1, lev2 and lev3 and placed my classes
in lev3.

package lev1.lev2.lev3;
class A {
public static void main(String[] args) {}

package lev1.lev2.lev3;
class B {

Now when I run A.class, I get the followign error:
java.lang.NoClassDefFoundError: lev1/lev2/lev3/A

Please help!!

Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
To run a class defined in a package, the root directory must be included in your classpath. For example, if you have the following structure:
Then the root directory "projects" must be in your classpath and you need to execute the program using the fully-qualified name:
e.g. "java lev1.lev2.lev3.A"

Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
I agree. Here's the link:
subject: Package woes
It's not a secret anymore!