java-runner

Run Java files from the terminal - no IDE required. Source: github.com/llerandi/java-runner

Compile and run Java in one command

No IDE, no build system, no project structure. Point it at a .java file and it handles the rest.

$ ./runner.sh FizzBuzz.java
 
▶ Compiling FizzBuzz.java...
✓ Compiled successfully
───────────────────────── output ─────────────────────────
1
2
Fizz
4
Buzz
Fizz
7
...
───────────────────────────────────────────────────────────
✓ Finished in 143ms
 
$ ./runner.sh FizzBuzz.java --watch
👁 Watch mode enabled - save the file to rerun

Single command

Wraps javac and java into one step. Compiles, runs, prints output, and cleans up.

Watch mode

Reruns automatically every time you save the file. Uses inotifywait on Linux, fswatch on macOS, FileSystemWatcher on PowerShell, and timestamp polling on Windows CMD.

Auto file detection

No argument needed if there is only one .java file in the directory. Falls back to examples/ automatically.

Clean error output

Strips absolute path noise from compiler errors so they are shorter and easier to read.

Elapsed time

Shows how long the program took to run after every execution, in milliseconds.

Cross-platform

runner.sh for Linux and macOS. runner.bat for Windows CMD. runner.ps1 for PowerShell with event-based watch mode.

Installation

Requires Java JDK 11 or higher. No other dependencies for the basic run.

git clone https://github.com/llerandi/java-runner.git cd java-runner chmod +x runner.sh

For watch mode on Linux, install inotify-tools:

sudo apt install inotify-tools

For watch mode on macOS, install fswatch:

brew install fswatch

Usage

./runner.sh HelloWorld.java # run a specific file ./runner.sh # auto-detect ./runner.sh HelloWorld.java --watch # watch mode ./runner.sh Main.java --all # compile all .java in the directory ./runner.sh Main.java --input in.txt # pipe file into stdin ./runner.sh Main.java --output out.txt ./runner.sh Main.java --classpath lib/junit.jar

On Windows CMD use runner.bat with the same flags. On PowerShell use .\runner.ps1 with -Watch, -All, -InputFile, -OutputFile, -Classpath.

Requirements

Tool Purpose Notes
Java JDK Compile and run Version 11+. Must include javac. Not just the JRE.
Bash 3.2+ Run runner.sh Linux and macOS only.
inotify-tools Watch mode on Linux sudo apt install inotify-tools
fswatch Watch mode on macOS brew install fswatch

Windows CMD users need no extra tools. Watch mode polls the file timestamp every 2 seconds. PowerShell users get event-based watch mode via runner.ps1 with no extra dependencies.

Output examples

Successful run:

▶ Compiling HelloWorld.java...
✓ Compiled successfully
───────────────────────── output ─────────────────────────
Hello, World!
───────────────────────────────────────────────────────────
✓ Finished in 98ms

Compilation error:

▶ Compiling FizzBuzz.java...
✗ Compilation failed:
 
FizzBuzz.java:6: error: ';' expected
        int x = 10
                   ^
1 error

Companion tool

Once you are comfortable running Java files, use java-kata-judge to validate your solutions with automated JUnit 5 tests - no Maven, no Gradle, no IDE required.

java-kata-judge site View on GitHub