java – NoClassDefFoundError: wrong name-ThrowExceptions

Exception or error:

I wrote a java program to test RESTful web services by using Netbeans7.0.1 and it works fine there. Now I wrote the build.xml file to compile the code and when I try to run the generated .class file I always got this exception:

Exception in thread "main" java.lang.NoClassDefFoundError: ClientREST (wrong name: clientrest/ClientREST)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(
    at java.lang.ClassLoader.defineClass(
    at Method)
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
Could not find the main class: ClientREST. Program will exit.

The name and path are correct, so any thoughts why I’m getting this exception?

How to solve:

Exception in thread “main” java.lang.NoClassDefFoundError: ClientREST

So, you ran it as java ClientREST. It’s expecting a ClientREST.class without any package.

(wrong name: clientrest/ClientREST)

Hey, the class is trying to tell you that it has a package clientrest;. You need to run it from the package root on. Go one folder up so that you’re in the folder which in turn contains the clientrest folder representing the package and then execute java clientrest.ClientREST.

You should not go inside the clientrest package folder and execute java ClientREST.


I encountered this error using command line java:

java -cp stuff/src/mypackage Test

where resides in the package mypackage.

Instead, you need to set the classpath -cp to the base folder, in this case, src, then prepend the package to the file name.

So it will end up looking like this:

java -cp stuff/src mypackage.Test


To further note on Garry’s reply: The class path is the base directory where the class itself resides. So if the class file is here –


You would need to reference the class path as follows:


So to run from the command line, the full command would be –

java -cp /home/person/javastuff/classes package1/subpackage/javaThing

i.e. the template for the above is

java_executable -cp classpath the_class_itself_within_the_class_path

That’s how I finally got mine to work without having the class path in the environment


Probably the location you are generating your classes in doesnt exists on the class path. While running use the jvm arg -verbose while running and check the log whether the class is being loaded or not.

The output will also give you clue as to where the clasess are being loaded from, make sure that your class files are present in that location.


Try the below syntax:

Suppose java File resides here: fm/src/com/gsd/

So you can run using the below syntax:

(Make current directory to ‘fm’)


Leave a Reply

Your email address will not be published. Required fields are marked *