How do I run java program with multiple classes from cmd?

javac *.java // compliles all java files in the dir

java MyClass // runs the particular file

If one class is dependent on another class that hasn’t been compiled yet, the program won’t run. So you should compile all files before trying to run the program dependent on other files.

If your files are packaged, then something like this

javac com.mypackage/.*java

java com.mypackage.MyClass

Leave a Comment