问题描述
我编写了一个java程序来使用Netbeans7.0.1测试RESTful Web服务,它在那里工作得很好。现在我编写了build.xml文件来编译代码,当我尝试运行生成的.class文件时,我总是遇到这个异常:
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(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
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?
推荐答案
因此,您将其作为 java ClientREST
运行。它预计 ClientREST.class
没有任何包
。
So, you ran it as java ClientREST
. It's expecting a ClientREST.class
without any package
.
嘿,班级试图告诉你它有一个包clientrest;
。您需要从包根目录运行它。转到一个文件夹,这样你就在文件夹中,而该文件夹又包含代表该软件包的 clientrest
文件夹,然后执行 java 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
.
你应该不进入 clientrest
包文件夹并执行 java ClientREST
。
You should not go inside the clientrest
package folder and execute java ClientREST
.
这篇关于NoClassDefFoundError:名称错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!