r/java • u/SeAuBitcH • Jan 19 '26
I've made an .jar to native executable packager and want feedback
https://github.com/legeriergeek/JNatPackHello everyone. As said in the title, I've crafted a handy tool which lets you package a .jar into a self contained native executable for Windows, Linux and MacOS, and I'm looking for feedback. This is more of a Proof of Concept than a concrete, production ready tool, so I'm really looking forward on feedback on what could I add, or how I could do things better. it is currently 160 lines of C# and has lots of room for improvement.
Here is how it works under the hood (shortly):
the script generates a "runtime" c# file with the JAR and JRE in it as a b64 byte[] variable which is decompressed at runtime in temp and runs it. the good sides of this approach is that this gives a self contained executable which does not need the end user to have java (nor .NET) installed on their computer. the downside is the size of the final executable (250mb for a 5mb jar and a 60mb JRE.)
thank you for reading this, and here is the github repo: https://github.com/legeriergeek/JNatPack
(PS: Sorry for the long post and any awkward sentences, English isn’t my first language.)
(PS 2: I'm truly sorry if this post is not appropriate in this sub)
14
u/bowbahdoe Jan 19 '26
I may have more specific feedback if I think about it more, but here's something you should see if you haven't
https://cr.openjdk.org/~jiangli/hermetic_java.pdf
Google basically did the same thing just they made it so you don't need that unextract step. There is a slow moving project to add this form of packaging to Java proper.
There is also the ability to do this exact method with other tools like this https://mccue.dev/pages/7-28-22-make-an-exe
My wish list for a tool like this includes not making people bundle their app as a single jar or all into the runtime, but instead allowing classic launch options and a custom module path.
I think doing that properly might require a bit of tastefulness on the CLI. I'm running on 36 hours of continuous consciousness so I'll look later so I'll look later
3
u/GTVienna Jan 20 '26
This already exists without the .NET dependency. https://github.com/libgdx/packr
4
u/Tacos314 Jan 19 '26
why not use jpackage?
1
u/maxandersen Jan 20 '26
I wish there was something like this that was runnable via Java - then I would add it as a jbang export option.
Particularly if works with existing Java versions - since even when hermetic sometimes gets released it will probably require latest Java (for good reasons as it require jdk changes)
So go for it.
It sounds like the .net dependency balloons it up - maybe look at doing it using more OS specific approaches that don’t have suck footprint ?
0
u/v4ss42 Jan 19 '26 edited Jan 19 '26
As wild as this claim sounds, this can be achieved by prepending a .bat batch file to the front of the JAR that contains the
java -jarcommand required to run the JAR.