-1

For a homework assignement i am begining to use Netbeans IDE to make enterprise applications . I was following the example given on the Oracle site here . I however ran into trouble with the following exceptions when i attempt to run my application :

    Caused by: java.lang.NoClassDefFoundError: cart/util/BookException
        at java.lang.Class.forName0(Native Method)
    ... 
Caused by: java.lang.ClassNotFoundException: cart.util.BookException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)

I read up this useful link and realise that this is a problem with my CLASSPATH environment variable . It was initially not set and i fear i am not setting it correctly .

I set the CLASSPATH to the following but doesnt work

C:\Windows\System32>set CLASSPATH
CLASSPATH=C:\Program Files\Java\jdk1.7.0_13\lib;C:\Program Files\Java\jdk1.7.0_1
3\jre\bin;.

Added a "." to include the current directory but i guess its not working . How do i make sure that my classes are found at runtime ?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
rockstar
  • 3,512
  • 6
  • 40
  • 63

1 Answers1

0

classpath should be set to the location of the classes, not the location of JDK as you set it. You confuse it with PATH variable. And if your classes are in the same directory as JDK you should probably move them out.

Let's say the java program you are trying to reference is in

C:\myproject\cart\util\BookException.java and you compile it to the same location, then the classpath would be C:\myproject\ If you compile it to a different location, say: C:\myproject\build\cart\util\BookException.class, then the classpath would be C:\myproject\build\

Roman Goyenko
  • 6,965
  • 5
  • 48
  • 81