12

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

jmj
  • 237,923
  • 42
  • 401
  • 438
Myn
  • 691
  • 4
  • 9
  • 19

2 Answers2

24

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

java -cp . ds.DiServer

And voilà.

gabuzo
  • 7,378
  • 4
  • 28
  • 36
  • I'm not in the office to test this anymore but I'll take your word on that and find out on Monday morning! Thank you both for great answers, if I could I'd choose both as the best but since there can only be one I'll give it to the one with the best explanation of the problem, which is this. Thank you very much again, your pint can be claimed at anytime :) – Myn Jan 07 '11 at 17:44
  • Yes it is unless you did include `.` in your `CLASSPATH` environment variable. – gabuzo Jan 11 '11 at 12:30
11

goto C:\My Documents\DiTest\ds\

javac  DiServer.java

goto C:\My Documents\DiTest\

java ds.DiServer 

Also See

jmj
  • 237,923
  • 42
  • 401
  • 438
  • and, if he's running it in eclipse, the first step should be unnecessary, just find the root of the output (bin) directory and run the java ds.DiServer from there. – KevinDTimm Jan 07 '11 at 14:45