如何减小JRE的大小?

Thu*_*rge 9 java

我最近尝试打包Java应用程序以便在Mac App Store中分发,但发现通过捆绑默认JRE,该应用程序将其文件大小增加了大约138 MB.我想通过剥离我不需要的组件(例如Corba,JavaFX,XML解析)来减小JRE的大小,因此当我将它捆绑到应用程序时会导致更小的增加.

有一些问题,比如这个问题,给出了一些关于要删除哪些组件的指导,但没有一个实际描述如何减少它.我需要做些什么来减小JRE的大小?有某些工具吗?我只是下载源代码并破解我不想要的类吗?我是否编辑了当前安装的JRE?我不确定从哪里开始.

ug_*_*ug_ 2

我自己还没有测试过,但经过一番搜索后,我发现了这一点。

打包Java 应用程序以在 Mac 上分发指南让您基本了解如何捆绑应用程序(听起来您已经掌握了)。从那里我遵循了应用程序捆绑程序的文档,在该页面上的“运行时”下,您可以看到可以在捆绑中明确包含或排除文件/文件夹。

根据他们的文档

"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."

我从中获取了他们的示例代码并添加了一条排除语句:

<-- 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>
Run Code Online (Sandbox Code Playgroud)

可选排除的完整列表可以在 JRE root - 中找到$JAVA_HOME/README.txt。查找文本Optional Files and Directories,您将位于其标题处。我正在查看计算机上的 JRE7 安装,JRE6 自述文件中似乎没有任何内容。

我知道这不适用于您正在寻找的示例,但我希望它可以帮助您弄清楚。