eclipse 线程“main”中的异常 java.lang.NoClassDefFoundError: DiServer <wrong name: ds/DiServer>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4626551/
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
Exception in thread "main" java.lang.NoClassDefFoundError: DiServer <wrong name: ds/DiServer>
提问by Myn
This is one of those terribly embarrassing questions I'm afraid.
恐怕这是非常令人尴尬的问题之一。
I have a program in Eclipse:
我在 Eclipse 中有一个程序:
package ds;
public class DiServer {
public static void main(String[] args) {
int foo = 0;
int bar = 0;
/*bla*/
}
}
Simple right? This works completely fine when run in Eclipse.
简单吧?这在 Eclipse 中运行时完全正常。
I want to run this from command line. I have copied bin Folder, with the ds folder inside it and DiServer.class in ds, and .classpath
我想从命令行运行它。我复制了 bin 文件夹,里面有 ds 文件夹,ds 中有 DiServer.class,还有 .classpath
I have put these into a separate folder, C:\My Documents\DiTest, opened command prompt, gone to C:\My Documents\DiTest\ds\ and typed java DiServer
我已将它们放入一个单独的文件夹 C:\My Documents\DiTest,打开命令提示符,转到 C:\My Documents\DiTest\ds\ 并键入 java DiServer
The error I get is Exception in thread "main" java.lang.NoClassDefFoundError: DiServer <wrong name:ds/DiServer> ... Could not find the main class: DiServer. Program will exit.
我得到的错误是 Exception in thread "main" java.lang.NoClassDefFoundError: DiServer <wrong name:ds/DiServer> ... Could not find the main class: DiServer. Program will exit.
I have tried java -classpath . DiServer, java -classpath ../.. DiServer, moving .classpath to the ds folder, but I can't seem to get round this. I'm 99% sure it's a classpath problem but I can't work out how to fix it.
我试过 java -classpath 。DiServer,java -classpath ../.. DiServer,将 .classpath 移动到 ds 文件夹,但我似乎无法解决这个问题。我 99% 确定这是一个类路径问题,但我不知道如何解决它。
I would greatly appreciate any help as always, and the customary offer of a pint always stands.
我会一如既往地感谢任何帮助,一品脱的习惯报价始终有效。
Thanks very much in advance,
首先十分感谢,
M
米
回答by gabuzo
You class full name is ds.DiServer
, not DiServer
. From C:\My Documents\DiTest
:
你班的全名是ds.DiServer
,不是DiServer
。来自C:\My Documents\DiTest
:
java -cp . ds.DiServer
And voilà.
和瞧。