16

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?

Community
  • 1
  • 1
user93353
  • 13,733
  • 8
  • 60
  • 122

4 Answers4

1

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.

Community
  • 1
  • 1
stackmagic
  • 164
  • 8
  • 1
    AFAIK This minimises the size of your application rather than the JRE. – Peter Lawrey Oct 18 '12 at 12:04
  • 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. – stackmagic Oct 18 '12 at 12:13
  • 1
    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? – Peter Lawrey Oct 18 '12 at 12:17
  • 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 Oct 18 '12 at 12:20
  • @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 Oct 18 '12 at 12:21
  • 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. – stackmagic Oct 18 '12 at 12:25
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

Community
  • 1
  • 1
Gabriel
  • 20,797
  • 27
  • 159
  • 293
0

I would make the JRE a separate install from Oracle (or your preferred vendor) You could have it download as required if you wish. If the JRE is already installed, it would be a waste to download it again even a reduced JRE.

BTW: I wouldn't mess with what is in the JRE because

  • AFAIK its a violation of your license agreement.
  • Its very difficult to get right and not remove a class you might need one day.
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • 1
    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. – user93353 Oct 18 '12 at 12:24
  • 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? – Peter Lawrey Oct 18 '12 at 12:26
  • re: The licence stuff. Do you know if this is still true? Was this specific to the JDK (as opposed to the OpenJDK?) – Pod Jul 13 '18 at 15:09
  • 1
    @Pod I don't believe the OpenJDK has any restrictions. You might be better off using that in your case. – Peter Lawrey Jul 13 '18 at 18:25
0

Maybe outdated: there was a rumor about something called JavaKernel/ConsumerJRE.

http://weblogs.java.net/blog/enicholas/archive/2007/05/java_kernel_unm.html

http://www.oracle.com/technetwork/java/javase/kernel-135055.html

Daniel Voina
  • 3,185
  • 1
  • 27
  • 32