I recently tried packaging a Java app for distribution in the Mac App Store, but discovered that by bundling the default JRE, the app increased its file size by about 138 MB. I would like to reduce the size of the JRE by stripping out components that I don't need (e.g. Corba, JavaFX, XML parsing), thus resulting in a smaller increase when I bundle it into an app.
There are a couple of questions, like this one, that give some guidelines about what components to remove, but none that actually describe how to go about reducing it. What do I need to do to reduce the size of the JRE? Are there certain tools? Do I just download the source and hack out the classes I don't want? Do I edit my currently installed JRE? I'm not really sure where to begin.
I havent tested this myself but after some searching heres what I have found.
The Packaging a Java App for Distribution on a Mac guide gives you a basic look at how to bundle the app (which it sounds like you got already). From there I followed the docs for app bundler, on that page under "runtime" you see you can explicitly include or exclude files/folders from the bundling.
According to their docs
"By default, only the contents of the jre/ directory will be included with the bundled application. All executable content (i.e. bin/, jre/bin/) is excluded. Additional content can be included or excluded using nested <include> and <exclude> elements, respectively."
From that I took their sample code and added an exclude statement:
<-- Import environment variables -->
<property environment="env"/>
<-- Define the appbundler task -->
<taskdef name="bundleapp" classname="com.oracle.appbundler.AppBundlerTask"/>
<-- Create the app bundle -->
<target name="bundle-swingset" depends="package">
<bundleapp outputdirectory="."
name="Test"
displayname="Test"
identifier="com.oracle.javafx.swing.Test"
shortversion="1.0"
applicationCategory="public.app-category.developer-tools"
mainclassname="com/javafx/main/Main">
<runtime dir="${env.JAVA_HOME}">
<exclude name="Java IDL Server Tool" /> <!-- exclude from bundle -->
</runtime>
<classpath file="${user.home}/bin/javafx-samples-2.2.0/SwingInterop.jar"/>
<option value="-Dapple.laf.useScreenMenuBar=true"/>
</bundleapp>
</target>
A full list of optional excludes can be found in the JRE root - $JAVA_HOME/README.txt
. Do a find for the text Optional Files and Directories
and you'll be at the header of it. I am looking at the JRE7 installation on my computer, the JRE6 readme didnt seem to have anything in it.
I know this isn't working the example you're looking for but I hope it helps you figure it out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With