JAVA Compiling via CMD

An issue i keep having is Compiling Java project created on IDE (Eclipse or Netbeans) on CMD line (Windows). I keep getting the issue


Error: Could not find or load main class <ClassName>


The thing is that, since it was built in IDE, and IDE would like to package it, it cannot be run on the .class directory.


Steps to follow.


  1. Make sure the PATH (Windows Env Variable) has JAVA bin path. If not, add it
  2. Try running javac from the command line. If succeed, you can compile using cmd line.
  3. Go to the src directory, up to the .java file.
  4. Compile it there
    1. javac
  5. Then to run it, go back to the src (source) directory, and then run command java packageName.ClassName .
  6. It should work

Directory of C:\Users\MM\Google Drive\PROGRAMMING\Java\MiniMusicCmdLine\src\minimusiccmdline

01/11/2017 07:31 AM <DIR> .
01/11/2017 07:31 AM <DIR> ..
01/11/2017 07:31 AM 1,203 MiniMusicCmdLine.class
01/09/2017 11:04 PM 1,377
2 File(s) 2,580 bytes
2 Dir(s) 904,655,876,096 bytes free

C:\Users\MM\Google Drive\PROGRAMMING\Java\MiniMusicCmdLine\src\minimusiccmdline>
java MiniMusicCmdLine
Error: Could not find or load main class MiniMusicCmdLine

C:\Users\MM\Google Drive\PROGRAMMING\Java\MiniMusicCmdLine\src\minimusiccmdline>
cd ..

C:\Users\MM\Google Drive\PROGRAMMING\Java\MiniMusicCmdLine\src>java minimusiccmd
Don’t forget the instrument and note args

C:\Users\MM\Google Drive\PROGRAMMING\Java\MiniMusicCmdLine\src>java minimusiccmdline.MiniMusicCmdLine

Leave a Reply

Your email address will not be published. Required fields are marked *