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

后端 未结 6 1859
梦如初夏
梦如初夏 2020-12-05 01:11

At the moment I am looking for another way to run my Java program from command line, other than adding it to a JAR file. My program has the following number of classes:

6条回答
  •  无人及你
    2020-12-05 01:51

    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
    

提交回复
热议问题