命令提示符中的 java.lang.NoClassDefFoundError

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11097760/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 03:46:34  来源:igfitidea点击:

java.lang.NoClassDefFoundError in command prompt

java

提问by happy

Possible Duplicate:
Can I run from command line program created by Eclipse?

可能的重复:
我可以从 Eclipse 创建的命令行程序运行吗?

I am getting below exception when I try to run class file from command prompt,the same I run in eclipse,there I don't get any error

当我尝试从命令提示符运行类文件时,我遇到了异常

Trying to run from the same folder

尝试从同一文件夹运行

 Exception in thread "main" java.lang.NoClassDefFoundError: testClient (wrong nam
    e: com/mindcraft/queryExecutor/actionclass/testClient)
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClassCond(Unknown Source)
            at java.lang.ClassLoader.defineClass(Unknown Source)
            at java.security.SecureClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.access
java com.mindcraft.queryExecutor.actionclass.testClient
0(Unknown Source) at java.net.URLClassLoader.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) Could not find the main class: testClient. Program will exit.

采纳答案by anthoon

Before posting a question kindly Search enough if the question has been asked before or even better answered before. When i Googled i found a similar questionbeing answered. Hope the link provides you the answer you are looking for

在发布问题之前,请搜索足够的问题,如果该问题之前已经被问过或者之前已经得到了更好的回答。当我用谷歌搜索时,我发现有人回答了类似的问题。希望链接为您提供您正在寻找的答案

回答by Jon Skeet

I suspect you're running ina directory of com/mindcraft/queryExecutor/actionclass

我怀疑你一个目录中运行com/mindcraft/queryExecutor/actionclass

Instead, you should be running in the root directory (i.e. the parent of com), like this:

相反,您应该在根目录(即 的父目录com)中运行,如下所示:

##代码##

回答by Chakri

run the .class file from root directory with full name space. i.e, if your class is in com.test package as com.test.App.java in your src then on compiling its class file will have a qualified class name as full name. i.e, com.test.App.class

从具有完整名称空间的根目录运行 .class 文件。即,如果您的类在 com.test 包中作为 com.test.App.java 在您的 src 中,那么在编译它的类文件时将有一个合格的类名作为全名。即,com.test.App.class

So from your root/src run it as java com.test.App in command line.

所以从你的 root/src 运行它作为 java com.test.App 在命令行中。