2014-02-09 90 views
8

我最近嘗試打包Java app for distribution in the Mac App Store,但發現通過綁定默認JRE,應用程序將其文件大小增加了大約138 MB。我想通過刪除不需要的組件(例如Corba,JavaFX,XML解析)來減小JRE的大小,從而在將它捆綁到一個應用程序中時產生較小的增加。如何縮小JRE的大小?

有一對夫婦的問題,比如this one,以獲得有關哪些組件,除去一些指引,但沒有實際描述如何去約減少它。我需要做些什麼來減小JRE的大小?有某些工具嗎?我是否只需下載源代碼並將我不想要的課程分解出來?我要編輯我當前安裝的JRE嗎?我不確定從哪裏開始。

+0

我不知道Mac商店,但是你不能不捆綁JRE嗎? 大多數人已經擁有它。事實上,我認爲它默認使用Mac電腦 –

+0

@Oxinabox蘋果在2010年左右停止在OS X中使用Java,因此只有那些出去下載它的人才擁有它。無論如何,Mac App Store要求所有應用程序都是自包含的,並且不需要默認安​​裝在OS X中的任何東西,因此JRE需要捆綁到應用程序中(最好不要添加138 MB)。 – Thunderforge

+0

也許它會自動檢測JRE是否已經安裝,如果沒有,然後去應用程序安裝過程中下載它? – Vitruvius

回答

2

我還沒有測試過這個,但經過一番搜索後,我發現了什麼。

Packaging a Java App for Distribution on a Mac指南爲您提供了關於如何捆綁應用程序的基本信息(它聽起來像您已經得到的)。從那裏我按照docs for app bundler,在那個頁面的「運行時」你看到你可以明確包含或排除捆綁文件/文件夾。

根據他們的文檔

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

可選排除的完整列表可在JRE根被發現 - $JAVA_HOME/README.txt。找到文本Optional Files and Directories,你會看到它的標題。我正在查看計算機上的JRE7安裝,JRE6自述文件似乎沒有任何內容。

我知道這不是你正在尋找的例子,但我希望它能幫你弄明白。