Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support running via Single-File Java Launcher (JEP 330) ? #1792

Open
foreverigor opened this issue Apr 4, 2024 · 5 comments
Open

Support running via Single-File Java Launcher (JEP 330) ? #1792

foreverigor opened this issue Apr 4, 2024 · 5 comments
Labels
ideas Some idea/suggestion around jbang behavior/feature set

Comments

@foreverigor
Copy link
Contributor

foreverigor commented Apr 4, 2024

Is your feature request related to a problem? Please describe.
JBang is great because it allows you to specify dependencies right in your script file.
However for cases where dependencies are not needed it will still build a jar from the source.
Since Java 11 the java launcher has the ability to launch such java source files directly: JEP 330: Launch Single-File Source-Code Programs

Describe the solution you'd like
When having access to a Java 11+ jvm, make the distinction for scripts which doesn't require any jbang-exclusive features and launch these directly with the java launcher, skipping the build step.
Some tags obviously require the jar to be built (anything involving dependencies or other sources), but others can be directly mapped to java options, like //JAVA, //RUNTIME_OPTIONS, some //COMPILE_OPTIONS

Describe alternatives you've considered
It's actually possible to run jbang scripts via the java launcher directly, but of course none of the jbang tags will be picked up

Additional context
Launching compatible source files directly has numerous advantages: We're saving one JVM launch and reduce first-time run times considerably. We also don't have to create a jar so we're skipping unnecessary disk writes & File I/O.

@foreverigor foreverigor added the ideas Some idea/suggestion around jbang behavior/feature set label Apr 4, 2024
@maxandersen
Copy link
Collaborator

Not sure it will make that big diff.

Are you saying jbang/java X.jar is noticably slower than java X.java?

@foreverigor
Copy link
Contributor Author

No, not running the jar. But the jar build process is what's slower. So, ./X.java vs java X.java. It's noticeable if you edit the script a lot

@maxandersen
Copy link
Collaborator

Yes I get that - but most will run not build.

Not having jar also means can't store which main methods to use or run any integration code (IE. Quarkus or jbang)

I'm not sure we can automatic detect if it's feasible - probably need an explicit flag.

//NOJAR ?

@quintesse
Copy link
Contributor

Too me this seems pretty fragile, we'd suddenly get possibly different behaviours depending on what code you're running (does it have dependencies or not?) and which JDK you're using (<11? compile to jar. 11? no jar, but only single file, 22? multiple files). I think that up to now we've tried hard to get the same behaviour everywhere across the board, so my first reaction at least would be -1. BUt I'm open to being convinced :-)

@foreverigor
Copy link
Contributor Author

I thought it was possible to just create a list of tags – those for which a jar is required and not. At least that was my idea when I glanced at the code.

different behaviours

Yes, that's also occured to me. Currently everything goes through the build jar -> run pipeline (except for jsh). Not sure how cleanly this branching could be implemented. I'll see what I can do myself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ideas Some idea/suggestion around jbang behavior/feature set
Projects
None yet
Development

No branches or pull requests

3 participants