Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
669 views
in Technique[技术] by (71.8m points)

eclipse - Exception in thread "main" java.lang.NoClassDefFoundError: DiServer <wrong name: ds/DiServer>

This is one of those terribly embarrassing questions I'm afraid.

I have a program in 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.

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

I have put these into a separate folder, C:My DocumentsDiTest, opened command prompt, gone to C:My DocumentsDiTestds and typed 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.

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.

I would greatly appreciate any help as always, and the customary offer of a pint always stands.

Thanks very much in advance,

M

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You class full name is ds.DiServer, not DiServer. From C:My DocumentsDiTest:

java -cp . ds.DiServer

And voilà.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...