Skip to content

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"); } }
Code language: Java (java)

To compile this, we simply do the following:

javac HelloWorld.java
Code language: Bash (bash)

Then when we need to run it, we do:

java HelloWorld
Code language: Bash (bash)

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
Code language: Bash (bash)

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

javac /some/directory/path/*.java
Code language: Bash (bash)

See also  How to create an AWS Lambda in Terraform
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x