2013-03-30 22 views
1

編輯:上述所有問題都可以通過創建一個帶有內置jvm參數的可執行jar來避免。一旦創建,我可以使用appbundler將它綁定到.app。我如何將VM參數集成到我的可執行文件.jar中?Eclipse Ant:使用appbundler將.jar捆綁到.app


我已經得到了我必須捆綁成使用appbundler通過甲骨文的.app可執行的JAR(使它在OS X上運行)。如果我使用java -XstartOnFirstThread -jar PhotoSelector.jar從終端啓動它,我的jar完美適用於OS X.由於SWT(封裝在我的可執行文件夾中)和Cocoa限制,我必須將-XstartOnFirstThread設置爲java參數。問題是我不知道如何正確配置Eclipse(Ant!)以將雙擊設置爲.app將使用-XstartOnFirstThread參數執行我的應用程序。這是我的XML文件:

在build.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
    <!-- WARNING: Eclipse auto-generated file. 
       Any modifications will be overwritten. 
       To include a user specific buildfile here, simply create one in the same 
       directory with the processing instruction <?eclipse.ant.import?> 
       as the first entry and export the buildfile again. --> 
    <project basedir="." default="build" name="PhotoSelector"> 
    <property environment="env"/> 
    <property name="ECLIPSE_HOME" value="../../../eclipse Java"/> 
    <property name="debuglevel" value="source,lines,vars"/> 
    <property name="target" value="1.7"/> 
    <property name="source" value="1.7"/> 
    <import file="buildMac.xml"/> 
    <path id="PhotoSelector.classpath"> 
     <pathelement location="bin"/> 
     <pathelement location="lib/swt_64_OsX.jar"/> 
    </path> 
    <target name="init"> 
     <mkdir dir="bin"/> 
     <copy includeemptydirs="false" todir="bin"> 
      <fileset dir="src"> 
       <exclude name="**/*.java"/> 
      </fileset> 
     </copy> 
    </target> 
    <target name="clean"> 
     <delete dir="bin"/> 
    </target> 
    <target depends="clean" name="cleanall"/> 
    <target depends="build-subprojects,build-project" name="build"/> 
    <target name="build-subprojects"/> 
    <target depends="init" name="build-project"> 
     <echo message="${ant.project.name}: ${ant.file}"/> 
     <javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}"> 
      <src path="src"/> 
      <classpath refid="PhotoSelector.classpath"/> 
     </javac> 
    </target> 
    <target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/> 
    <target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler"> 
     <copy todir="${ant.library.dir}"> 
      <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/> 
     </copy> 
     <unzip dest="${ant.library.dir}"> 
      <patternset includes="jdtCompilerAdapter.jar"/> 
      <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/> 
     </unzip> 
    </target> 
    <target description="compile project with Eclipse compiler" name="build-eclipse-compiler"> 
     <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/> 
     <antcall target="build"/> 
    </target> 
    <target name="Main"> 
     <java classname="com.selector.Main" failonerror="true" fork="yes"> 
      <classpath refid="PhotoSelector.classpath"/> 
     </java> 
    </target> 
</project> 

BuildMac.xml

<?eclipse.ant.import?> 
<project name="PhotoSelectorBundler"> 
<taskdef 
name="bundleapp" 
classname="com.oracle.appbundler.AppBundlerTask" 
classpath="lib/appbundler-1.0.jar" /> 

<target name="bundle"> 
<bundleapp 
    outputdirectory="dist" 
    name="PhotoSelector" 
    displayname="Photo Selector" 
    identifier="com.selector.Main" 
    mainclassname="Main" 
    icon="src/com/selector/256.icns"> 
    <classpath file="dist/PhotoSelector.jar" /> 
</bundleapp> 
</target> 
</project> 

所以,我的問題是:

  1. 如何通過 - 雙擊時,XstartOnFirstThread默認爲.app?
  2. 至於目標我必須在eclipse ant工具中選擇導出我的.app正確嗎?

現在我的.app被創建,但它立即關閉。我使用appbundler,因爲Jar Bundler不支持Java 1.7(在我的項目中廣泛使用)。謝謝!

回答

3

如何在雙擊時將-XstartOnFirstThread默認傳遞給.app?

添加您<bundleapp>標籤上的以下內容:

<option value="-XstartOnFirstThread"/> 

至極目標我必須選擇在eclipse螞蟻工具正常導出我的.app?

我不確定你到底在問什麼。推測這將是你的bundleapp目標。請參閱Jar Bundler documentation以獲得逐步指導。

請注意,Mac應用程序是一個擴展名爲「.app」的目錄。在該目錄裏面你會找到Contents/Info.plist文件。這將包含您的JVM參數和其他Java相關信息。如果你仍然有問題,這可能是一個開始調查的好地方(它也可以幫助其他人回答你的問題)。

+0

工作完美!爲了讓我的.app工作,我添加了另一行:'''(swt庫的路徑)。即使庫被封裝到我的可執行jar中,我也必須將它添加到.app中。我發現你不能將JVM參數傳遞到可執行文件jar中,因爲它們是命令行中的運行時選項。謝謝! – Angelo