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

0 min read 124 words

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:

javac HelloWorld.java

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
Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags

Recent Posts