How to Compile Multiple Java Files From a Single Command in Java

  • Home /
  • Blog Posts /
  • How to Compile Multiple Java Files from a Single Command in Java

If you need to compile multiple Java files using a single command, then you can do the following.

First, it’s good to learn how to compile a Java file.

How to Compile a Java File

Let’s take the following Java code:

class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello World");

To compile this, we simply do the following:


Then when we need to run it, we do:

java HelloWorld

We now get the output of Hello World.

How to Compile All Java Files in the Current Directory

If you have multiple files in your current directory, then you can issue the following command:

javac *.java

Alternatively, you can specify a directory where your Java files live:

javac /some/directory/path/*.java