0

So I made a project with packages in Eclipse. I have a few classes all in same package com.example.parser. In Eclipse everything works fine. So I wanted to run one of the class from command line. The java/javac PATHs are set correctly and work normally if no packages are there. The file structure looks like this:

~Project/bin/com/example/parser/*.class (all class files)
~Project/src/com/example/parser/*.java (all source files)

So in command line I go to ~Project/bin/com/example/parser To mention OS: Windows 7 Pro The command java ClassToRun gives

Exception in thread "main" java.lang.NoClassDefFoundError: ClassToRun (wrong name:
com/example/parser/ClassToRun) at ... (stack trace)

So I googled a bit and got to conclusion this is the correct command: java -cp .;~Project/bin ClassToRun Now I get this:

Error: Could not find or load main class ~Project/bin

So I could not solve this... any one can help a bit? PS: Forgot to mention the "/" should be "\" and the "~" stands for the abs path infront. Oh yeah and I just update to jdk 1.7...

Alex Botev
  • 1,369
  • 2
  • 19
  • 34
  • There's a few ways this could go wrong, and a few details missing. The devil may be in the details here. Consider providing current working dir and command lines. – Richard Sitze Jul 27 '12 at 00:31
  • @RichardSitze: I think the devil here is a couple of missing double quotes, along with the special importance of the semicolon for the Windows command prompt... – thkala Jul 27 '12 at 07:12
  • @thkala: comment made under your answer. – Richard Sitze Jul 27 '12 at 07:54

2 Answers2

2

Did you type the fully-qualified class name at the command prompt?

i.e.

java -cp .;~Project\bin name.of.package.Class
Chris S.
  • 100
  • 3
  • Yes, thanks for the tip... after whole the night I did setting up my java environment this never crossed my mind :) – Alex Botev Jul 27 '12 at 23:04
0

.metadata is corrupted.

Steps:

Stop eclipse, delete .metadata in workspace and restart eclipse

Import Project

Run again

(Details)

Community
  • 1
  • 1
iCrazybest
  • 2,935
  • 2
  • 24
  • 24