NoClassDefFoundError:错误的名称 [英] NoClassDefFoundError: wrong name

查看:18
本文介绍了NoClassDefFoundError:错误的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个 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?

推荐答案

线程main"中的异常 java.lang.NoClassDefFoundError: ClientREST

Exception in thread "main" java.lang.NoClassDefFoundError: ClientREST

因此,您将其作为 java ClientREST 运行.它需要一个 ClientREST.class 没有任何 package.

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

(错误名称:clientrest/ClientREST)

(wrong name: clientrest/ClientREST)

嘿,这个类试图告诉你它有一个 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:错误的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆