Monday, March 31, 2014

could not find or load main class [java]

If you got this error "could not find or load main class" trying to execute your freshly compiled java program you have a problem with your classpath variable that doesn't include your current folder.
Solution:

Open the Control Panel -> System -> Advanced System Settings -> Advanced [table] -> environment variables and then "edit" your CLASSPATH adding a dot "." at the end.

PS
You have to re-open your Windows console to make the change active.

From the Oracle documentation
"The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings."

No comments:

Post a Comment

Your comment will be visible after approval.