jr - Modern JAR launcher with JDK 25 AOT support (started off as a native build of jbang ended up making this) #2328
Replies: 3 comments 35 replies
-
|
interesting ideas and thanks for reminding me about PATHEXT and that windows has both java.exe and javaw.exe - something I kinda forgot about as its not used anywhere else. I like your idea of having name of exe drive which jar to run - combined with the small size its a nice little detail. Your project reminds me of the jbang-launch (https://github.com/jbangdev/jbang-launch) and that we now have native image of jbang (just not enabled in the jbang scripts yet) - I assume the PATHEXT trick should work as is with jbang. With respect to AOT what do you actually do to have the training run ? |
Beta Was this translation helpful? Give feedback.
-
|
Another way to reduce JBang's start-up time and the program it runs, is to use JVM option -XX:TieredStopAtLevel=1 for both. Both JBang and the Java application will only use the client JIT. The total running time was reduced by 0.5 seconds in a quick test that I performed. One could argue that -XX:TieredStopAtLevel=1 should be the default for JBang.{cmd,sh,ps1} |
Beta Was this translation helpful? Give feedback.
-
I am just sharing, as a matter of personal experience, I am appreciative of this concern, however I have implemented a simple method to clean old AOT cache and it works for me. And also I don't claim it will fit all use cases ... but i am surprised what is such a big complication in implementing a solution to cleanup aot files ... after all they can be regenerated. I don't see why old AOT files need to be left bloating. If they haven't been accessed for a certain period of time especially they can be cleaned. What i have implemented is, if source has changes (and i am proposing one more addition that if jdk has changed) ... it regenerates AOT and cleanups old AOT. Right now my implementation keeps only one AOT file at any given time because in my use case any app will be run with only one jdk not multiple ... i don't see such a use case arising for me. Again I am clarifying, I am not disputing the concern ... I am just wondering, it seem trivial to solve, and feeling it shouldn't be a big worry, especially given as you said it can be experimental feature to start with, and use activated flag (not default). And to indicate my use case, I could make a alias/shortcut script called jbx which runs jbang with aot. if i need normal jbang i would just do jbang .. this way i keep invocation syntax short and simple for myself. At the same time, in windows as a i explained we can associate java files with either java, jbang or say jbx, and configure PATHEXT ; thus java files become executable. the jbang file additionally could have |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I built a small Windows launcher for Java apps called "jr" (jar runner / java runner / something short (and small - jr - junior) therefore named in two letters like uv for python).
It's basically what Launch4j and WinRun4J do, it launches JAR files as native Windows executables, but it is a very simplified implementation, with few extra features which you will definitely love. The basic idea is to run your jars as if exe - literally both in terms of execution friendliness, raw performance, and even ease of development/deployment/configuration.
Unique Features
1. AOT - Ahead of Time
JR supports out of box JDK 25 AOT cache generation, use and cleanup.
AOT can make huge impact in startup performance, depends on use case, in certain tests noticed about 90% faster (20-30ms vs 200-300ms).
With JDK 25 and AOT enabled, first run takes ~200-300ms to create the cache, then subsequent runs are 20-30ms. The launcher overhead itself is only 2-3ms measured via performance counters.
2. Make Jars executable both in command line and guis:
The same exe (jr.exe) has two ways it can be used. One way is to use it as a dedicated launcher for a specific (fat) jar (or a custom complex java command) based on a simple .jrc config format (key=value, similar to WinRun4J etc). This feature is very much like the standard launch4j/winrun4j feature with extra automatic AOT. So basically you can rename this to yourapp.exe and put yourapp.jar next to it, and generate a jrc config file ... and that yourapp.exe becomes a launcher exclusively for yourapp.jar.
But there is another (arguably more interesting) use case!
This tool works as a generic replacement for java/javaw.exe to launch jar files. It auto-detects if your app needs a console window or should run as GUI (delegated to java or javaw accordingly) and it either keeps the console window visible or hidden based on this detection. (Caveat: There is a brief flashing of console window in pure GUI context and I don't know how to even hide that brief flash without spoiling the experience of pure CLI execution.)
Configuration steps:
PATHEXT.Usually it looks like this
You can make it:
Now with this configuration the jar files will become executable like exe/batchfiles just by using their name, and will work from anywhere if they are in the path!
This marks your end in making batch files for easy execution. Even jbang uses a jbang.cmd even maven uses mvn.cmd ... these can now work directly from jar or custom configuration ... upto you. You are freed and liberated from non-java companions you need to make your execution experience feel native.
Side note in
PATHEXTyou can even include .java and link it with jbang (out of box AOT support currently out of scope of this tool however):This makes your jar files really behave like native exes ... both in execution friendliness, invocation from gui or commandline, and also in terms of raw performance due to AOT.
Also you avoid the fragile, long, tedious build process of GraalVM (native image) which additionally gives a large sized exe which we dislike anyway. This gives you best of several worlds ... yes you don't get your java exe in 20KB ... that is not going to happen, it still depends on installed JVM ... but (I guess) this is as good as it can get. Can we do better? I wonder.
3. Bonus: Small EXEs
The exe is quite minimalist, simple and small (~23 KB with vcredist dependency, or ~193 KB standalone with no dependencies)
What jr lacks:
Anyway, thought some of you might find it useful. Feedback welcome.
The code is open source, written in plain C with no dependencies. It is a single source file, and builds with MS VC Build Tools portable. There are some Java test files for AOT performance testing and general JR tool testing.
Repo: https://github.com/xyz-jphil/jr
Beta Was this translation helpful? Give feedback.
All reactions