From the folder that represents the base of your package hierarchy, assuming your entry point class is called Main, in a package called app,

javac -classpath . app/Main.java

should generate the correct class definitions. The compiler will ferret out the dependencies and compile whatever other classes are needed. The class files will appear in the same directory as their source files.

If, as you say, you have 'more than one entry' class, you will have to at least identify all those top level classes from the dependency hierarchy, which can be listed as further params to javac, specifying the packages as they occur. Like so, assuming you also need to start with other.Entry

javac -classpath . app/Main.java other/Entry.java 

Note that you will still have to figure out which of your classes are tops of independent dependency hierarchies, whether you are creating an ant script or doing it this way.

Answer from JustJeff on Stack Overflow
🌐
Florida State University
cs.fsu.edu › ~myers › cop3252 › howto › cmdline.html
Compiling on the Command line with Java SDK
The primary Java SDK tools, which can be accessed from a command prompt/shell, are: javac // the compiler java // loader/interpreter Windows versions of these filenames would be:
🌐
GeeksforGeeks
geeksforgeeks.org › java › compilation-execution-java-program
Compilation and Execution of a Java Program - GeeksforGeeks
October 14, 2025 - Geeks.java is the file to compile. ... If there are no errors, this command will create a file called Geeks.class. The .class file contains bytecode, which is a platform-independent code that the JVM can execute. If there are errors, the compiler will show them in the terminal.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › specs › man › javac.html
The javac Command
January 20, 2026 - Source files to be compiled (for example, Shape.java) or the names of previously compiled classes to be processed for annotations (for example, geometry.MyShape). The javac command reads source files that contain module, package and type declarations written in the Java programming language, ...
🌐
W3Schools
w3schools.com › java › java_getstarted.asp
Java Getting Started
Open Command Prompt (cmd.exe), navigate to the directory where you saved your file, and type "javac Main.java": C:\Users\Your Name>javac Main.java · This will compile your code. If there are no errors in the code, the command prompt will take ...
Find elsewhere
🌐
Quora
quora.com › How-do-you-compile-a-Java-project-which-consists-of-multiple-Java-files-on-the-command-line-command-prompt-terminal
How to compile a Java project which consists of multiple Java files on the command line (command prompt/terminal) - Quora
For that just give the command cd(change directory). C:\Users\RAJ MAITY.LAPTOP-4O4D1GH5>cd Codingprograms · You need to give the name of the folder in which you have saved the java file. In my case it is Codingprograms. ... Here you go, the program have been compiled and ran by the command prompt.
🌐
Coderanch
coderanch.com › t › 477671 › build-tools › compile-single-java-class-Mvn
To compile single java class using Mvn thru command line (Other Build Tools forum at Coderanch)
Hi All, I want to compile single java class in my project.Is there any process to do like this.Because I do update only single class for some time repeatedly and I don't want to recompile all the project.So, Could you please suggest me If we have such facility and I appreciate if you send specific procedure. Thanks in advance. ... Maven (and Ant) will only compile classes that have changed. ... Honestly, I don't know--check the docs for the "compile" command.
🌐
Medium
medium.com › @AlexanderObregon › executing-java-code-from-the-command-line-d6a3c09bb565
Executing Java Code from the Command Line | Medium
March 9, 2025 - If the compilation is successful, a new file named HelloWorld.class will appear in the same directory. This file contains the bytecode representation of your program. The javac command does more than just convert .java files into .class files.
🌐
OneCompiler
onecompiler.com › java
Java Online Compiler
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter your name: "); String inp = input.next(); System.out.println("Hello, " + inp); } }
🌐
freeCodeCamp
freecodecamp.org › news › how-to-execute-and-run-java-code
How to Execute and Run Java Code from the Terminal
March 10, 2022 - We need to use the command javac file_name_with_the_extension. For example, as I want to compile my Main.java, I will use the command javac Main.java.
🌐
Wikihow
wikihow.com › computers and electronics › software › programming › java › how to compile and run a java program using command prompt
How to Compile and Run a Java Program Using Command Prompt
September 28, 2025 - At the command prompt, type "cd" followed by the path your Java program is saved to, then press "Enter." Type "javac [filename] and press "Enter" to compile the program.
🌐
Coderanch
coderanch.com › t › 725429 › java › Compile-Run-Java-program
Compile & Run Java program (Beginning Java forum at Coderanch)
I wrote a trivial class: It's ... try to compile with -cp: What's going on? All things are lawful, but not all things are profitable. ... The -cp option is for classes, not source files. It stands to reason that if you want to run a single source file application, you simply specify its path relative to the current working directory, rather than using a separate command line switch to first specify the source directory: ... It doesn't seem to be explicitly stated in the docs but javac expects the ...
🌐
UCSC
users.soe.ucsc.edu › ~eaugusti › archive › 102-winter16 › misc › howToCompileAndRunFromCommandLine.html
How to compile and run a Java Program from the command line
Change directory (cd) to the directory that contains the source file(s) (.java) that you want to compile. Enter the following command (note that you can compile single or multiple files by name or wildcards): javac -Xlint:unchecked SourceFile.java Running Java Programs From the Command Line
🌐
BeginnersBook
beginnersbook.com › 2013 › 05 › first-java-program
How to Compile and Run your First Java Program
To compile the program, type the following command and hit enter. ... You may get this error when you try to compile the program: “javac’ is not recognized as an internal or external command, operable program or batch file“. This error occurs when the java path is not set in your system
🌐
Baeldung
baeldung.com › home › java › core java › compiling java *.class files with javac
Compiling Java *.class Files with javac | Baeldung
January 8, 2024 - Let’s execute the following command in the directory containing the structure provided in the previous section: javac -d javac-target com/baeldung/javac/Data.java · The javac compiler will generate the class file javac-target/com/baeldung/javac/Data.class.
🌐
Dummies
dummies.com › article › technology › programming-web-design › java › how-to-use-the-javac-command-172116
How to Use the javac Command | dummies
July 1, 2025 - The javac command in Java compiles a program from a command prompt. It reads a Java source program from a text file and creates a compiled Java class file.
🌐
Princeton CS
introcs.cs.princeton.edu › java › 11hello
1.1 Your First Java Program: Hello World
Create the program by typing it into a text editor and saving it to a file named, say, MyProgram.java. Compile it by typing "javac MyProgram.java" in the terminal window.