java main class not found code example

Example 1: java error main class could not be found

For me the issue was that my classpath was not set correctly, then you have to add the classpath with -cp:
java -cp <Full Directory / FilePath> <Name of the ClassFile>

Example 2: > Task :run FAILED Error: Could not find or load main class Caused by: java.lang.ClassNotFoundException:

Check your build.gradle file and update the application block:

application {
    // Define the main class for the application.
  	// insert the entire name of the class
    mainClassName = 'packageName.MainClass'
}

Example 3: Error: Could not find or load main class -Djava.library.path=.home.hdoop.hadoop-3.3.0.lib.native

Sounds silly, but if you've copied .bashrc lines from somewhere
check that the quotation marks are like this:
    export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib/native"
and not like this
    export HADOOP_OPTS=-Djava.library.path=$HADOOP_HOME/lib/native...took me some time

Tags:

Java Example