A minimal Stripped Down JRE for Windows

12,071

Solution 1

There is a possible solution here. Those tools install a minimalistic version of Java. I don't know if it is small enough for you. Just take a look and see: https://superuser.com/questions/745112/how-do-i-run-a-jar-file-without-installing-java

Solution 2

Avian and ProGuard are your friends as someone has already mentioned in one of the threads you linked to (it's the second comment btw).

From the Avian homepage:

The class library is designed to be as loosely coupled as possible, allowing tools like ProGuard to aggressively isolate the minimum code needed for an application. This translates to smaller downloads and faster startup.

Sounds like exactly what you need. And if that doesn't help you then look at the rest of the tools referenced in that thread.

Share:
12,071
user93353
Author by

user93353

Updated on June 06, 2022

Comments

  • user93353
    user93353 almost 2 years

    I have an application in the form of a jar file which is around 2MB in size. For several reasons, I have to bundle the JRE with my application. When I create an MSI with my jar and the JRE, the MSI size comes out to be around 30MB.

    I am looking for a commercial or free JRE which I can bundle so that I can reduce the size of my MSI to as low as possible. I am looking at 5MB total, but even upto 10MB may be OK. Prebuilt JRE Binaries would be great, but not an absolute must.

    I looked at similar questions posted here and here.

    A lot of answers in these and other threads suggest Excelsior. I downloaded an evaluation version of Excelsior JET & Tried it out - for a few reasons, I think it may not be the right product for me.

    1) Excelsior looks at reducing the footprint of the Installed Product not the Installer. I don't care much about the size of the Installed Product - I am mainly looking at a smaller download (the installer of my product currently at 30MB).

    2) Amongst other things, Excelsior does lot of optimizations to code to achieve this - I don't want my jar file touched at all. I want a smaller JRE with my jar as is. There isn't a way to turn off some of the optimisations also.

    3) Excelsior creates an EXE - I am not particularly looking for this - I am ok with my product being invoked via the javaw.exe command line.

    So are there any suggestions for my need?

  • Vishy
    Vishy over 11 years
    AFAIK This minimises the size of your application rather than the JRE.
  • stackmagic
    stackmagic over 11 years
    The "application" in this case is the sum of his own code plus the class library and whatever other libs he uses. That's what ProGuard can optimize and what Avian is (as quoted in my answer) explicitly designed for.The rt.jar on my system is 50MB, if you only ever use String and some Collections then ProGuard will be able to remove a whole lot from that jar file alone.
  • Vishy
    Vishy over 11 years
    So if you run your application in a different time zone or with a different default character encoding, how does it work out whether these might be needed?
  • user93353
    user93353 over 11 years
    I had looked at both of them. I haven't tried Avian yet because it doesn't seem to have JRE pre-built binaries - you need to build them. (i'll edit it and add prebuilt to my original question) I am going to try if there are no good pre-built options available. About Proguard, I am not sure if it's what I am looking for - it talks about optimisations - I assume its going to optimisations in my code not the JRE & remove unnecessary stuff. I am looking to shrink my jar file. May be I misunderstanding it but that's what I got from their webpage.
  • user93353
    user93353 over 11 years
    @stackmagic Does proguard remove stuff from the JRE - is that even allowed as per Sun's license (Sun has a small list of stuff you can remove without violating the license)? Also my program size is trivial as compared to the size of the JRE. Even if I shrink down my program to a Hello World, it's not going to make much of difference to the overall size of my MSI.
  • user93353
    user93353 over 11 years
    As I said in the post, I have my reasons to bundle. Also, Sun/Oracle has a list of stuff which it allows you to remove from the JRE without violating the license, but I tried it - it doesn't make that much of a different.
  • stackmagic
    stackmagic over 11 years
    I don't know and I've never used this myself -- I'm merely suggesting this is something that might provide a solution and should be investigated.
  • Vishy
    Vishy over 11 years
    I don't see how you can test that it will never be needed even if it happens to work for you on one machine. BTW are you shipping a windows 32-bit, 64-bit, Linux and Mac OS versions as well?
  • Pod
    Pod almost 6 years
    re: The licence stuff. Do you know if this is still true? Was this specific to the JDK (as opposed to the OpenJDK?)
  • Vishy
    Vishy almost 6 years
    @Pod I don't believe the OpenJDK has any restrictions. You might be better off using that in your case.