feat: run modular jars as modules + full --module grammar - #2662
Draft
maxandersen wants to merge 6 commits into
Draft
maxandersen wants to merge 6 commits into
maxandersen wants to merge 6 commits into
Conversation
Modular jars (e.g. com.netflix:com.netflix.tools.jfmt) often declare their main class in module-info.class instead of a Main-Class manifest entry (some ship without any manifest, where 'java -jar' fails with 'Invalid or corrupt jarfile'). JBang now checks the module descriptor before falling back to scanning the jar for main() candidates, so such jars run directly without prompting the user to pick a main class.
When --module is used with a jar whose main class comes from the module descriptor (or a scanned class), emit '-m <module>[/<main>]' so the JVM runs it as a named module, instead of appending a bare class name to the module path (which left the code in the unnamed module).
… match - In --module mode with no explicit main, keep emitting a bare '-m <module>' and never scan (the JVM resolves the descriptor main). Test hardened to use a manifest-less jar (like real modular jars) and assert no '<module>/<main>'. - A glob --main now works in module mode too: it bypasses the descriptor, scans classes, and emits '-m <module>/<chosen>'. - A single (glob-matched) candidate now runs without an interactive prompt, making glob search usable non-interactively.
- adopt java's -m <module>[/<mainclass>] grammar for the --module value - jbang extensions: empty module part (/Class) derives the module from the jar; the class part may be a glob to search for - default (no flags): a manifest-less jar with a module-descriptor main-class now runs as a module (was classpath), matching how it was packaged - single (glob-matched) main candidate auto-runs without an interactive prompt - conflicting main (--module=x/Y and --main Z) is rejected - no jbang-side unknown-module pre-check (launched name can validly differ from enumerable module names); JVM reports it at runtime TestModuleLaunch adds an executable spec for the grammar + anti-cases.
- add 'Classpath vs module execution' section with the full --module[=module[/class-or-glob]] grammar table and mode-selection rules - note the --module vs -m/--main distinction - update main-class detection docs: single scanned/glob candidate now runs without prompting
Contributor
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one) (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Reverts the single-candidate auto-select: a glob (or ambiguous scan) is a request to choose, so it always prompts; running automatically requires an explicit main class. Restores the candidate-list behaviour for a lone match and updates the module glob tests + docs accordingly.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Makes JBang run modular JARs the way they were packaged, and gives
--modulethe fullmodule[/mainclass]grammar (java's own-msyntax, plus two small JBang extensions).Why
A modular CLI whose main class lives only in
module-info.class(with noMain-Classmanifest entry) — e.g.com.netflix:com.netflix.tools.jfmt— could not be run sensibly:java -jarfails outright (no manifest), andServiceLoaderproviders, strong encapsulation, and the module version (jfmt reportsdevon the classpath vs0.8.2as a module).Behaviour
Execution mode now follows where the main class comes from:
Main-Classmanifest-m <module>)--moduleforces module execution and accepts java'smodule[/mainclass]grammar, with two JBang extensions — an empty module part derives the module from the jar, and the main class may be a glob:jbang run app.jarjbang run -m com.acme.Main app.jarcom.acme.Mainon classpathjbang run --module app.jar-m <jarModule>jbang run --module=some.mod/com.acme.Main app.jar-m some.mod/com.acme.Mainjbang run --module=some.mod/com.acme.* app.jarjbang run --module=/com.acme.Main app.jarjbang run --module --main com.acme.Main app.jar--module=/com.acme.MainSemantics
--module=x/Yand--main Zis rejected.ModuleFinderenumerates (automatic names, unbuilt jars, custommodule-info), so this is left to the JVM. (See ponytail note inJarCmdGenerator.)Tests / docs
TestModuleLaunch— executable spec (13 cases) for the grammar + anti-cases.TestJarMainDetection; updatedTestModule/TestRunfor the new defaults.running.adoc— new "Classpath vs module execution" section with the grammar table.Note
Builds cleanly on top of the jandex 3 upgrade in #2661 (needed to scan modern class files); no dependency between the diffs beyond
JarCmdGenerator.