首页 > 解决方案 > 用于 Mac 的 Java 应用程序包不处理参数

问题描述

我正在更新旧版 Java 应用程序,以便它与 Java 8 一起运行。我正在使用 ant 和 JavaFX。这个应用程序需要一组参数。我已经指定了参数,它们出现在生成的 cfg 文件中,但是,当通过单击图标启动应用程序时,它们不会被处理。通过命令行启动应用程序时会处理这些参数。

蚂蚁脚本:

<project name="xxxxxx" default="default" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">

  <property name="JAVA_HOME" value="/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home"/>

  <echo message="JAVA_HOME: ${JAVA_HOME}" />

  <property name="build.src.dir" value="src"/>
  <property name="build.classes.dir" value="classes"/>
  <property name="build.dist.dir" value="dist"/>
  <property name="build.java.resources.dir" value="../Contents/Java"/>

  <target name="default">

    <taskdef resource="com/sun/javafx/tools/ant/antlib.xml" uri="javafx:com.sun.javafx.tools.ant" classpath="${JAVA_HOME}/lib/ant-javafx.jar"/>

    <fx:application id="xxxxxx" name="xxxxxx" mainClass="com.xxxx">
          <fx:argument>-application com.xxxxx.Application -image xxxxxx/splashscreen.jpg -background black -title xxxxx -dock_icon ../application.icns -mem_max 1024</fx:argument>
    </fx:application>

    <fx:resources id="appRes">
          <fx:fileset dir="${build.dist.dir}" includes="Startup.jar"/>
    </fx:resources>

    <fx:jar destfile="${build.dist.dir}/Startup.jar">
          <fx:application refid="xxxxxxx"/>
          <fx:resources refid="appRes"/>
          <fx:fileset dir="${build.classes.dir}"/>
    </fx:jar>

    <fx:deploy width="300" height="250"
           outdir="./deploy" embedJNLP="false"
           outfile="xxxxxxx"
           signBundle="false"
           nativeBundles="all">

           <fx:application refId="xxxx"/>

           <fx:resources refid="appRes"/>

           <fx:info title="xxxxx" vendor="xxx"/>
    </fx:deploy>
   </target>
 </project>

生成的cfg:

[Application]
app.name=xxxxx
app.mainjar=Startup.jar
app.version=1.0
app.preferences.id=xxxx
app.mainclass=com/xxxx/SplashScreen
app.classpath=
app.runtime=$APPDIR/PlugIns/Java.runtime
app.identifier=xxxx

[JVMOptions]

[JVMUserOptions]

[ArgOptions]
-application com.xxx.Application -image com/xxx/splashscreen.jpg -background black -title xxxx -dock_icon ../application.icns -mem_max 1024

任何线索表示赞赏。

标签: javamacosjavafxantbundle

解决方案


看起来每个参数都需要单独指定,例如:

    <fx:argument>-application</fx:argument>
    <fx:argument>com.xxxx.Application</fx:argument>
    <fx:argument>-image</fx:argument> 
    <fx:argument>com/xxxx/splashscreen.jpg</fx:argument> 

推荐阅读