ClassNotFoundException pops up when there is a class file

File directory

$ pwd
/Users/apple/Desktop/springt/javacTest
$ tree
.
 src
     com
         subject
             math
                 Hi.class
                 Hi.jav

Hi,java file

package com.subject.math;

 public class Hi{
    public static void main(String args[]){
        System.out.println("hi");
    }
}

but after the compilation is complete, ClassNotFoundException:

appears.
$ java /Users/apple/Desktop/springt/javacTest/src/Hi.class
Error: Could not find or load main class .Users.apple.Desktop.springt.javacTest.src.Hi.class
Caused by: java.lang.ClassNotFoundException: /Users/apple/Desktop/springt/javacTest/src/Hi/class

Why do I compile successfully but fail to run?

Mar.02,2021

cannot be executed in full path unless the path is a package name, and running a bytecode file does not need to wait for class, to execute the following:
enter the directory: / Users/apple/Desktop/springt/javacTest/src
execute: java Hi

if there is a package name: java package name path / Hi

Menu