Skip to content

Java 22: Launch multi-file source-code programs (JEP 458) - #125

Open
mperor wants to merge 1 commit into
masterfrom
DAILY/113-multi-file-source-launcher
Open

mperor wants to merge 1 commit into
masterfrom
DAILY/113-multi-file-source-launcher

Conversation

@mperor

@mperor mperor commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

What you'll learn

  • How java GreetingMain.java (the source-code launcher) automatically finds and compiles a sibling .java file it references, with no explicit javac step and no build file
  • That compilation is on-demand: a broken sibling file in the same directory is simply never touched if nothing references it
  • How this contrasts with the single-file-only launcher introduced in Java 11 (JEP 330), which had no notion of resolving a dependency living in another source file

Why it matters

JEP 458 makes small, multi-class scripts and prototypes just as easy to run as a single-file program - handy for quick experiments, teaching examples, and utility scripts that don't warrant a full Gradle/Maven project.

Read more

JEP 458: Launch Multi-File Source-Code Programs

Quiz

A directory has Main.java (which calls Helper.greet()) and Broken.java, which has a syntax error and is never referenced. Does java Main.java succeed?

AnswerYes. The source-code launcher only compiles the files it actually needs to resolve references from the entry file, transitively - `Broken.java` is never compiled because nothing reaches it, so its syntax error has no effect.

Note: tests were not run locally. The build requires a JDK 25 toolchain, which Gradle's foojay auto-provisioning tries to download from api.foojay.io; that host is blocked by this environment's network policy, and no JDK 25 is otherwise installed here (only JDK 21). The multi-file resolution logic and expected output were verified locally with the available JDK by compiling the sibling files explicitly and running the resulting classes; the single-file-launcher invocation itself (java GreetingMain.java, auto-resolving Greeter.java) is a JDK 22+ capability that could not be exercised directly in this environment. Opening as a draft so CI (which runs on JDK 25) can verify.

Closes #113

@mperor mperor added the daily Queued for the daily learning PR label Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Test Results

308 tests  +2   305 ✅ +2   6s ⏱️ ±0s
 84 suites ±0     3 💤 ±0 
 84 files   ±0     0 ❌ ±0 

Results for commit adfbe35. ± Comparison against base commit 40465e6.

@mperor
mperor marked this pull request as ready for review November 9, 2026 07:23
@github-actions

Copy link
Copy Markdown

@mperor ⏰ This daily topic is still waiting for your review.

4 similar comments
@github-actions

Copy link
Copy Markdown

@mperor ⏰ This daily topic is still waiting for your review.

@github-actions

Copy link
Copy Markdown

@mperor ⏰ This daily topic is still waiting for your review.

@github-actions

Copy link
Copy Markdown

@mperor ⏰ This daily topic is still waiting for your review.

@github-actions

Copy link
Copy Markdown

@mperor ⏰ This daily topic is still waiting for your review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

daily Queued for the daily learning PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Java 22: Launch multi-file source-code programs (JEP 458)

2 participants