17

I created a JavaFX application, For it I bundled it As a self-contained standalone application, using a private copy of Java Runtime.

But this became my application's size of 166MB, in which 146 Mb size is for jre.

How can I reduce the size of my application or can say size of bundle Runtime JRE?

I read somewhere that some files are optional in jre, So I tried to run my application after removing those files but unable to run the application.

So how can I remove the unused files/folders/modules from the Runtime JRE for my application ?

It is said that

Only a subset of Java Runtime is included by default. Some optional and rarely used files are excluded to reduce the package size, such as all executables. If you need something that is not included by default, then you need to copy it in as a post-processing step.

So by default it is not adding all the files in jre, in that case my application is not running. Application.jar is working fine as it is using system jar. So I add all the reamaining files in post-processing step.

Thanks

Ronak Jain
  • 2,402
  • 2
  • 24
  • 38
  • 1
    Maybe you can try out ProGuard (http://proguard.sourceforge.net/) It also can remove unused fields, classes ("shrink"). – Adrian Jan 30 '13 at 07:34
  • Btw, is there a reason you package Java with your application and not letting the user install it? – Adrian Jan 30 '13 at 07:36
  • 3
    For the peoples which don't want to install java on there system. – Ronak Jain Jan 30 '13 at 08:02
  • 1
    Take a look at this: http://stackoverflow.com/questions/4387266/reducing-size-of-jre?rq=1 and – keuleJ Jan 30 '13 at 08:06
  • I think the real question is, why is 166 MB such an untenable size? That's *maybe* a few pennies of hard drive space. Is this going on some embedded device? – Thorn G Jun 25 '13 at 14:13
  • I'm just shooting in the dark here, but couldn't you create a standalone, executable, **minimized** JAR simply with the maven shade plugin? – D. Kovács Jan 30 '17 at 11:28
  • I just tried a hello world app and used `javafxpackager -makeall -appclass application.Main -name test` to create an executable. It's a whopping 189mb folder. Want to use this for a simple app for a client without extra installation instructions. I have to think about another solution. – A.W. Jul 25 '18 at 11:16

3 Answers3

3

Project Jigsaw appears to have some hope for helping with this.

But it looks to be coming in Java 9 at the earliest.

So as far as I can understand from your post, you can't run your app with the reduced JRE size that JavaFX provides. Additionally, you tried the steps detailed here and you still can't run your app.

Many apps can run just fine with the limited number of classes available in the JavaFX packaging of the JRE. Perhaps you can examine what Java libraries you are using which cause this issue. Then you could explore alternatives to those libraries. Finally you would need to test whether those alternative libraries are larger or smaller than the space reduction provided by the reduction in the JavaFX packaging.

Community
  • 1
  • 1
Splaktar
  • 5,506
  • 5
  • 43
  • 74
  • Please provide a reason for downvote so that the answer can be improved. Especially when downvoting a 4 year old answer. – Splaktar Apr 20 '17 at 23:01
  • 2
    There seems to be people just downvoting because they are bored. There’s nothing we can do about it. I don’t see anything in your answer that needs to be improved, though, while theoretically true, I wouldn’t expect much from any attempt of bundling a JavaFX application with a downsized JRE, even with Jigsaw, simply because JavaFX itself *is* the biggest module of the JRE. – Holger May 17 '17 at 09:50
0

If you are using JavaFX ant tasks to assemble you bundle, then just define the basedir attribute as an empty string in the platform element, like in this example:

        <fx:platform basedir="">
            <fx:jvmarg value="-Xmx768m" />
        </fx:platform>

This will package your application and its dependencies but not the JRE itself.

Martins
  • 1,231
  • 2
  • 14
  • 17
0

Unfortunately, removing unused files is not possible with Java 8.

To reduce the Application Size you can use the native OS installers.

Windows Exe Installer should have size around 50 MB and the Mac OS X DMG Installer around 60MB.

VoteAlex
  • 1
  • 2