【问题标题】:Eclipse Ant: bundle .jar into .app using appbundlerEclipse Ant:使用 appbundle 将 .jar 捆绑到 .app
【发布时间】:2013-04-02 05:35:25
【问题描述】:

编辑: 可以通过创建带有内置 jvm 参数的可执行 jar 来避免上述所有问题。创建后,我可以使用 appbundle 将其捆绑到一个 .app 中。如何将 VM 参数集成到我的可执行 .jar 中?


我有一个可执行的 jar,我必须使用 Oracle 的 appbundler 将其捆绑到一个 .app 中(以使其在 OS X 上运行)。如果我使用java -XstartOnFirstThread -jar PhotoSelector.jar 从终端启动它,我的 jar 可以在 OS X 上完美运行。由于 SWT(打包在我的可执行 jar 中)和 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(在我的项目中广泛使用)。谢谢!

【问题讨论】:

    标签: java eclipse ant jvm-arguments jarbundler


    【解决方案1】:

    双击时如何默认将-XstartOnFirstThread传递给.app?

    &lt;bundleapp&gt; 标签内添加以下内容:

    <option value="-XstartOnFirstThread"/>
    

    我必须在 eclipse ant 工具中选择哪些目标才能正确导出我的 .app?

    我不确定你在这里问什么。大概这将是您的bundleapp 目标。请参阅Jar Bundler documentation 获取分步指南。

    请注意,Mac 应用程序是一个扩展名为“.app”的目录。在该目录中,您将找到 Contents/Info.plist 文件。这将包含您的 JVM 参数和其他 Java 相关信息。如果您仍然遇到问题,这可能是开始调查的好地方(它也将帮助其他人回答您的问题)。

    【讨论】:

    • 完美运行!为了让我的 .app 工作,我添加了另一行:&lt;classpath file="lib/swt_64_OsX.jar"/&gt;(swt 库的路径)。即使该库被打包到我的可执行 jar 中,我也必须将它添加到 .app 中。我发现您不能将 JVM 参数传递到可执行 jar 中,因为它们是命令行中的运行时选项。谢谢!
    猜你喜欢
    • 2012-04-10
    • 2012-03-12
    • 2014-06-26
    • 2011-10-30
    • 2015-10-12
    • 2014-10-08
    • 2012-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多