-1

I want to run a java file in windows command prompt instead of the IDE. I have a file named Names.java and compiling with javac Names.java works fine. Nevertheless, after compiling this file, I get an Error when I want to run that file withjava Names. This ist the Error:

Error: Could not  find or load main class Names
Caused by: java.lang.NoClassDefFoundError: myFiles/Names (wrong name: Names)

(FYI: myFiles is the name of my package I created in Eclipse)

Bizarrely, it works fine if I run the .java-file with java Names.java , but I need to run the compiled .class-file.

aslanj
  • 71
  • 6

3 Answers3

0

Assuming your project looks like this:

  Desktop/
    myFiles/
      Names.java

On the shell, you cd to your Desktop folder, and compile the file

> javac myFiles/Names.java

To run your class, you stay on your Desktop folder, and provide the full name of your class (includes the pacakge name)

> java myFiles.Names

That should run your Names.main() method

Slawomir Chodnicki
  • 1,525
  • 11
  • 16
0

use command java Classname in your case you have run command as given below

Java Names

there is not need of .java while running class file

0

cd ..

java myFiles.Names

Then it should work.

Also read Error: Could not find or load main class

9716278
  • 2,044
  • 2
  • 14
  • 30