NoClassDefFoundError: wrong name

我与影子孤独终老i 提交于 2019-11-26 11:48:41

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 Test.java 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 -

/home/person/javastuff/classes/package1/subpackage/javaThing.class

You would need to reference the class path as follows:

/home/person/javastuff/classes

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.

ShivaMahesh

Try the below syntax:

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

So you can run using the below syntax:

(Make current directory to 'fm')

java src.com.gsd.FileName

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!