How to reduce the size of the JRE?

I recently tried packing a Java application for distribution on the Mac App Store , but found that by bundling a standard JRE, the application increased its file size by about 138 MB. I would like to reduce the size of the JRE by removing components that I don’t need (for example, Corba, JavaFX, XML parsing), which leads to a smaller increase when connecting it to the application.

There are several questions, such as this one , that give some recommendations on which components to remove, but no one describes how to do this. What do I need to do to reduce the size of the JRE? Are there any specific tools? Am I just loading the source and pulling out classes that I don't need? Can I change the currently installed JRE? I'm not sure where to start.

+8
java
source share
1 answer

I did not test it myself, but after looking for what I found.

Distributing a Java application for distribution on a Mac gives you a basic look at how to bundle an application (which looks like you already have). From there I followed the docs for the app bundler , on this page in the runtime section you see that You can explicitly include or exclude files / folders from the set.

According to their documents

"By default, only the contents of the jre/ directory will be included with the bundled application. All executable content (ie bin/, jre/bin/) is excluded. Additional content can be included or excluded using nested <include> and <exclude> elements, respectively."

I took my sample code from this 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 complete list of optional exceptions can be found in the JRE root directory - $JAVA_HOME/README.txt . Do a search for the text Optional Files and Directories , and you will be taken to its title. I am looking at installing JRE7 on my computer, the JRE6 readme seems to have nothing.

I know this does not work on the example you are looking for, but I hope this helps you figure it out.

+2
source share

All Articles