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...

4

2 回答 2

2

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

i.e.

java -cp .;~Project\bin name.of.package.Class
于 2012-07-27T00:18:58.563 回答
0

.metadata is corrupted.

Steps:

Stop eclipse, delete .metadata in workspace and restart eclipse

Import Project

Run again

(Details)

于 2014-12-02T06:23:43.453 回答