Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

eclipse

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 Documents\DiTest, opened command prompt, gone to C:\My Documents\DiTest\ds\ 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

like image 435
Myn Avatar asked Jan 07 '11 14:01

Myn


2 Answers

You class full name is ds.DiServer, not DiServer. From C:\My Documents\DiTest:

java -cp . ds.DiServer

And voilà.

like image 66
gabuzo Avatar answered Nov 13 '22 12:11

gabuzo


goto C:\My Documents\DiTest\ds\

javac  DiServer.java

goto C:\My Documents\DiTest\

java ds.DiServer 

Also See

  • packages
like image 21
jmj Avatar answered Nov 13 '22 12:11

jmj