How can I reduce the size of fat jar?
I have an application that uses javafx and jsoup, and when exporting the jar file using shadow jar it weighs 8.7 mb, but I think this is too much for a very lightweight application.
Is there any way to reduce the size of this file, or any gradle plugins?(preferably for 24 java, but not necessary)
14 Replies
⌛ This post has been reserved for your question.
Hey @Prostoblodi! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
Are you building the same JAR for Windows, Linux and MacOS?
The biggest part of JavaFX are the native parts which are different for these
So instead of including them all in a single fat JAR, you can create three JARs
no, the jar I'm building is only suitable for linux
yeah JavaFX is fairly big
I assume you are using Scene Builder?
unfortunately, I don't know what you're talking about(
actually 8MB is very small for a JavaFX application
I wanted to know whether you are using FXML files
no, I'm not using FXML files
javafx-controls is around 2.5MB and javafx-graphics is around 4.9MB
both of them are needed
You could ofc try some shrinking/dead code elimination but I think that would do almost nothing with JavaFX
Also JavaFX doesn't even support fat JARs
like I don't even think native-image would reduce much
So no I don't think you can get much smaller with JavaFX
One thing you could do is not distributing any JAR file but a jlink image - that would be bigger but your users wouldn't need to install a JDK/JRE
(that's the recommended way to package JavaFX applications as fat JARs aren't supported as mentioned earlier)
but I kinda made a working fat jar with javafx
if that's not possible, should I close this ticket?
yes you can kinda get it working but classpath deployments are not supported
I mean there are things you could try like an obfuscation/shrinking tool
that looks for things that aren't needed and removes them
but idk how well that would work
you could also try using native-image with the native-image agent but that would probably be quite a bit of work and might result in a bigger executable (though one that doesn't need Java to run)
For that specifically - I'd close the post if you have no more questions about it - but you don't have to close it if you don't want to
are there any such tools for java 24? I've only found tools for 17
proguard should support JDK 24 AFAIK
with version 9.1.10 or later
ok, thanks, I'll try again later, sorry I can't right now
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.