Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac Terminal: Could not find or load main class CLASSNAME

I am trying to run a java program through the Terminal on Mac, yet getting:

Error: Could not find or load main class (MY CLASSNAME)

I compiled this application with Eclipse, and when I run this with Eclipse, it works fine. Furthermore, I am in the right directory, as when I type "ls" in the Terminal, it lists all the files, includes the class file I am trying to run.

This is what I type:

java mainClass

I would very much appreciate help to solve this!

Thank you,

Dean

EDIT: Solution - instead of java mainClass, it must have package too: java startPackage.mainClass

like image 618
Dean Leitersdorf Avatar asked Jun 12 '14 00:06

Dean Leitersdorf


People also ask

Could not find the main class main program will exit?

Problem: Error "Could not find the main class - program will exit" on the ServiceDesk configuration while configuring Web Services. Cause: This happens when there are multiple java versions installed and the value of NtfsDisable8dot3NameCreation is incorrectly set.


1 Answers

Start by making sure you are at the directory above the top level package

If the class belongs to the package com.foo.bar, you want to be in the directory above com.

In your case, you want to be in the directory above startPack.

Then you need to use the fully qualified name to run the class...

java statPack.mainClass

For example...

like image 135
MadProgrammer Avatar answered Sep 20 '22 20:09

MadProgrammer