'unable to compile and run a java program with multiple source files on the command line

I am trying to compile and run a java program that has 3 source files, and I am not able to get it to run.

I have a folder with 3 java source files, Tester.java, CommandHandler.java, and DualList.java. Tester.java contains the main function, and depends on CommandHandler.java, which depends on DualList.java

I tried to compile the program with javac Tester.java CommandHandler.java DualList.java. It created the three class files, but when I try to run the program with java -cp . Tester I get the following error:

Error: Could not find or load main class Tester
Caused by: java.lang.NoClassDefFoundError: cmsc420_s22/Tester (wrong name: Tester)

I can see that the class file is there, and I got no errors during compilation, so I'm not sure what is going on. I think it might be a problem with my java installation or my configuration. I'm doing this on a kali linux WSL distribution. I haven't changed anything about my installation, and I set my classpath to the current folder so I'm not sure what's wrong

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source