Shrinking rt.jar

who has done it? (I know cas did.)
using which tool ?
to which result ?

JET seems to be able and somehow proguard too, can’t get that working though

when is jigsaw supposed to be… “done” ?

With the Oracle JRE, I’m pretty certain you have to redistribute it, unaltered. So you can’t alter rt.jar.

But I’d imagine you can get around it with OpenJDK!

Yeah until jigsaw thats the legal situation.
But wasn’t interested in a legal discussion - thats a whole different story.

You can just open it in a file extractor (such as WinRAR or 7-zip) and just remove the bits you don’t use. As long as you never touch those classes, I would imagine you can get away with it.

Finding out which you don’t use could be found using one of the various Java dependency analyzers. I’ve not tried any of them myself, so I don’t know if they include all core Java classes.

You could also try one of the solutions here on Stack Overflow for getting a list of all loaded classes at runtime.

A third alternative would be to attach JVisualVM (which you’ll find in the JDK) to your Java application, and perform a ‘heapdump’. In the heapdump, on the ‘classes’ tab, you have a list of all classes and how many instances are there for each class. As most classes have 0 instances, I would expect that is a list of all of the classes that are loaded.

I simply ran my game with -verbose:class > classes.txt on the command line, which gives you a complete list of every single class loaded. Play the game for a bit to make sure you’ve got them all, then:

  • Strip all the other output that got mixed in: I just used Textpad to sort the entire output
  • Strip out everything that isn’t from rt.jar from the list
  • A bit more munging will basically give you a list of classnames loaded from rt.jar
  • Then write a quick zippy util thing to simply read in rt.jar, ditch classes not in the list, and re-output a smaller rt.jar

In the end, saves 30mb. But hardly worth the effort to be honest in this day and age. Times changed.

Cas :slight_smile:

yeah…
Duly noted.

43.7MB is still quite big for today’s average internet speeds.

The whole JRE 7z is only <20mb.

This isn’t good approach… it might work but fails when another set of classes are needed at runtime, eg. when used in Windows under different locale, I can imagine more of such cases. And indeed, I saw some LWJGL demo that just did that and while worked for others, it failed for me (I don’t remember exactly why but I think it was because of the localized Windows).

The only valid approach is to dig into OpenJDK internals, reveal dependencies and classes that are treated specially and reduce size of rt.jar based on that info. I even think Sun already did such analysis with the modularized JRE.

well
if you distribute a mini game, you most likely dont ship a jre anyway
if you distribute something big, its already big anyway. shouldn’t matter then if it’s 400 or 500 megs or whatever
and yeah an installer which compresses to 7zip might also help…

Really? Where are you at? Because I’ve got average/slow broadband for the uk but happily downloaded the Space Marine demo a few days ago and that clocks in at 1.3Gb. I don’t think 40Mb is anything to worry about these days.

40mb isn’t really a whole lot these days, I can download a 40mb file in under 40 seconds usually.

most of the time you know roughly the packages you are using, you can just open the rt.jar (with a zip program) and delete some of the big packages that you are sure you won’t need (e.g. XML, Corba, RMI, SQL, and if your using LWJGL the Java2D and Audio packages can go too), doing so can easily knock of 20-30mb, which makes rt.jar much smaller. This should avoid needed classes getting deleted (mostly) and only takes a few minutes to do manually. Using Pack200 and 7z on the rest should pretty much make the rt.jar overhead insignificant.

The above method doesn’t trim rt.jar as finely as say what princec mentions above, but should easily get rt.jar down to being just a 5-10mb addition to your download. I have in the past seen someone (think it was oNyx/aho) get rt.jar down to just 3mb (without pack200 and 7z) and have their LWJGL game work with it but not sure how that was done :slight_smile:

Actually I cheated and left out a few steps which covered getting those few extra classes as well. Also I am only interested in certain locales.
I did get JDK1.4.2 down to 2.5mb, with RMI still in it :slight_smile:

Cas :slight_smile:

40MB is nothing for my internet speeds but in the US, the average internet speeds is < 4Mbps

Don’t underestimate the cost of distributing such massive files.

Currently around $1.30 :slight_smile:

Cas :slight_smile:

$1.00/GB sounds like a decade ago. These days it’s more like between $0.01 and $0.10 per GB, depending on whether you pick a regular webhost / cloud service (expensive), or a content-delivery-network (cheap).

And for those claiming they pay $20 for unlimited bandwidth/traffic, please remember that when you’re actually transfering ‘a lot’ of data, your cheap-ass hoster will either cap your bandwidth, dig up some FUP policy or find another way to prevent himself from going bankrupt, or well, go bankrupt, in which case you’re also cut off.

Indeed, I have my maths wrong, I’m actually paying $0.13 for 1.3GB (maxcdn.com)

Cas :slight_smile: