#How can I reduce the size of fat jar?

33 messages · Page 1 of 1 (latest)

copper rapids
#

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)

celest elmBOT
#

This post has been reserved for your question.

Hey @copper rapids! Please use /close or the Close Post button 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.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

tough trout
#

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

copper rapids
tough trout
#

yeah JavaFX is fairly big

#

I assume you are using Scene Builder?

copper rapids
#

unfortunately, I don't know what you're talking about(

tough trout
#

actually 8MB is very small for a JavaFX application

#

I wanted to know whether you are using FXML files

copper rapids
tough trout
#

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

tough trout
#

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

tough trout
copper rapids
#

but I kinda made a working fat jar with javafx

copper rapids
tough trout
tough trout
#

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)

tough trout
copper rapids
tough trout
#

proguard should support JDK 24 AFAIK

#

with version 9.1.10 or later

copper rapids
#

ok, thanks, I'll try again later, sorry I can't right now