简体   繁体   English

如何减小JRE的大小?

[英]How do I reduce the size of the JRE?

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. 我最近尝试打包Java应用程序以便在Mac App Store中分发 ,但发现通过捆绑默认JRE,该应用程序将其文件大小增加了大约138 MB。 I would like to reduce the size of the JRE by stripping out components that I don't need (eg Corba, JavaFX, XML parsing), thus resulting in a smaller increase when I bundle it into an app. 我想通过剥离我不需要的组件(例如Corba,JavaFX,XML解析)来减小JRE的大小,因此当我将它捆绑到应用程序时会导致更小的增加。

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? 我需要做些什么来减小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? 我是否编辑了当前安装的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). 在Mac上分发Java App for Distribution指南可以让您基本了解如何捆绑应用程序(听起来就像您已经拥有的那样)。 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. 从那里我跟着app bundler文档,在“运行时”下的那个页面上,你看到你可以从捆绑中明确地包含或排除文件/文件夹。

According to their docs 根据他们的文档

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

From that I took their sample code and added an exclude statement: 从那里我拿了他们的示例代码并添加了一个exclude语句:

<-- 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 . 可以在JRE根目录中找到可选排除的完整列表 - $JAVA_HOME/README.txt Do a find for the text Optional Files and Directories and you'll be at the header of it. 找到文本Optional Files and Directories ,你将在它的标题。 I am looking at the JRE7 installation on my computer, the JRE6 readme didnt seem to have anything in it. 我正在看我的计算机上的JRE7安装,JRE6自述文件似乎没有任何内容。

I know this isn't working the example you're looking for but I hope it helps you figure it out. 我知道这不是你正在寻找的例子,但我希望它可以帮助你搞清楚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM