简体   繁体   中英

Eclipse Ant: bundle .jar into .app using appbundler

Edit: all the problem above can be avoided by creating an executable jar with built-in jvm arguments. Once created, I can bundle it into a .app using appbundler. How can I integrate VM arguments into my executable .jar?


I've got an executable jar that I've got to bundle into a .app using appbundler by Oracle (to make it work on OS X). My jar works perfectly on OS X if i launch it from the terminal using java -XstartOnFirstThread -jar PhotoSelector.jar . Due to SWT (packaged in my executable jar) and Cocoa restrictions, I've got to set -XstartOnFirstThread as a java argument. The problem is that I don't know how to configure properly Eclipse (Ant!) to set that double click to .app will execute my app using -XstartOnFirstThread argument. These are my XML files:

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>

So, my questions are:

  1. How to pass -XstartOnFirstThread to .app by default when double clicking?
  2. Wich targets I've got to select in eclipse ant tool to export my .app correctly?

Right now my .app is created but it closes immediately. I use appbundler because Jar Bundler doesn't support Java 1.7 (widely used in my project). Thank you!

How to pass -XstartOnFirstThread to .app by default when double clicking?

Add the following inside your <bundleapp> tag:

<option value="-XstartOnFirstThread"/>

Wich targets I've got to select in eclipse ant tool to export my .app correctly?

I'm not sure exactly what you are asking here. Presumably it would be your bundleapp target. Please refer to the Jar Bundler documentation for a step-by-step guide.

Note that a Mac app is a directory with the extension ".app". Inside of that directory you will find Contents/Info.plist file. This will contains your JVM args and other Java related info. If you continue to have problems this may be a good place to start investigating (and it would help others to answer your question as well).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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