没有JRE的JavaFX DEB捆绑包不起作用

时间:2016-03-06 12:40:56

标签: java linux javafx deb

我使用Oracle“自包含应用程序打包”工具为JavaFX 8桌面应用程序创建.deb文件。可以在Ubuntu上安装生成的包文件而不会出现问题但是应用程序无法运行。该文件安装如下:

$ sudo dpkg -i vocabhunter-1.0.14.deb

但是,尝试运行该应用程序会生成以下错误:

$ /opt/VocabHunter/VocabHunter
VocabHunter Failed to locate JNI_CreateJavaVM
VocabHunter Failed to launch JVM

重要的是,我在没有包含JRE的情况下生成捆绑包,并且在调查中似乎问题与此有关。生成的文件/opt/VocabHunter/app/VocabHunter.cfg包含以下行:

app.runtime=

如果我编辑它并添加Java路径,程序将毫无问题地启动。作为一种解决方法,我建议在安装.deb软件包后,用户运行以下命令:

sudo sed -i "s|app.runtime=.*|app.runtime=$JAVA_HOME|g" /opt/VocabHunter/app/VocabHunter.cfg

但是,这会让用户感到困难。有谁知道如何修复JavaFX打包工具的配置以避免这个问题?

构建使用Gradle调用Ant脚本来生成捆绑包。 Gradle填写所有必要的变量。 Ant脚本如下:

<project name="VocabHunter Packaging" basedir=""
         xmlns:fx="javafx:com.sun.javafx.tools.ant">
    <property environment="env"/>
    <property name="JAVA_HOME" value="${env.JAVA_HOME}"/>
    <target name="jfxbundle" description="Build the application bundle">
        <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
                 uri="javafx:com.sun.javafx.tools.ant"
                 classpath="${JAVA_HOME}/lib/ant-javafx.jar"/>
        <fx:deploy outdir="${basedir}/build"
                   nativeBundles="${packageType}">
            <fx:platform basedir=""/>
            <fx:application id="VocabHunterId"
                            name="VocabHunter"
                            mainClass="${mainClass}"
                            version="${version}"/>
            <fx:resources>
                <fx:fileset dir="${basedir}/build/libs"/>
            </fx:resources>
            <fx:info title="VocabHunter">
                <fx:association description="VocabHunter session"
                                extension="wordy"
                                mimetype="application/x-vnd.VocabHunterSession"
                                icon="${sessionIcon}"/>
            </fx:info>
            <fx:bundleArgument arg="icon"
                               value="${appIcon}"/>
            <fx:bundleArgument arg="mac.CFBundleVersion"
                               value="${version}"/>
            <fx:bundleArgument arg="launcher-cfg-format"
                               value="prop"/>
        </fx:deploy>
    </target>
</project>

您可以在上下文here中看到完整的脚本。

我在Ubuntu 14.04上使用JDK 1.8.0_92对此进行了测试。

1 个答案:

答案 0 :(得分:2)

要在此处回答这个问题,您需要设置JRE_HOME来运行某些本机JavaFX启动程序,而不必捆绑JRE。在Windows上,它查看注册表内部并搜索HKLM\Software\JavaSoft\Java Runtime Environment\[CurrentVersion]\JavaHome我找不到任何关于此的文档。

要解决此问题,您需要“更新”app.runtime - 值作为安装时正在执行的postinst脚本的一部分。像这样:

#!/bin/sh
# postinst script for APPLICATION_NAME
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

case "$1" in
    configure)
        echo Adding shortcut to the menu
SECONDARY_LAUNCHERS_INSTALL
APP_CDS_CACHE
        xdg-desktop-menu install --novendor /opt/APPLICATION_FS_NAME/APPLICATION_LAUNCHER_FILENAME.desktop
FILE_ASSOCIATION_INSTALL

        if [ "SERVICE_HINT" = "true" ]; then
            echo Installing daemon
            cp /opt/APPLICATION_FS_NAME/APPLICATION_PACKAGE.init /etc/init.d/APPLICATION_PACKAGE

            if [ -x "/etc/init.d/APPLICATION_PACKAGE" ]; then
                update-rc.d APPLICATION_PACKAGE defaults

                if [ "START_ON_INSTALL" = "true" ]; then
                    if which invoke-rc.d >/dev/null 2>&1; then
                        invoke-rc.d APPLICATION_PACKAGE start
                    else
                        /etc/init.d/APPLICATION_PACKAGE start
                    fi
                fi
            fi

        fi

        if [ -f /etc/profile ]; then
            # load special environment variables
            . /etc/profile

            # remove stored value in case of dpkg-reconfigure
            RUNTIME_PATH_TO_SET=""

            if [ -z "$JRE_HOME" ]; then
                echo JRE_HOME is not set, checking for JAVA_HOME being set
                if [ -z "$JAVA_HOME" ]; then
                    echo JAVA_HOME is not set, checking for known locations

                    # look for known locations
                    KNOWN_JDK_DIRS="/usr/lib/jvm/java-8-oracle /usr/lib/jvm/java-8-openjdk-amd64 /usr/lib/jvm/java-8-openjdk-i386"
                    FOUND_JAVA_HOME=""

                    # Look for the right JVM to use (use the first one)
                    for potentialjdkdir in $KNOWN_JDK_DIRS; do
                        if [ -r "$potentialjdkdir/bin/java" -a -z "$FOUND_JAVA_HOME" ]; then
                            FOUND_JAVA_HOME="$potentialjdkdir"
                        fi
                    done

                    if [ -z "$FOUND_JAVA_HOME" ]; then
                        # still nothing found :(
                        echo Please make sure to have Java installed and JRE_HOME variable set before running APPLICATION_LAUNCHER_FILENAME
                    else
                        echo Updating runtime-settings using known location
                        RUNTIME_PATH_TO_SET="$FOUND_JAVA_HOME"
                    fi
                else
                    echo Updating runtime-settings using JAVA_HOME
                    # JAVA_HOME is set, use that value
                    RUNTIME_PATH_TO_SET="$JAVA_HOME"
                fi
            fi

            # always write runtime-location, as it might get removed again when user calls dpkg-reconfigure
            sed -i "s|app.runtime=.*|app.runtime=$RUNTIME_PATH_TO_SET|g" /opt/APPLICATION_FS_NAME/app/APPLICATION_LAUNCHER_FILENAME.cfg
        fi
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0

使用javafx-maven-plugin或javafx-gradle-plugin时,将此脚本放在src/main/deploy/package/linux内,文件名为postinst,以便javapackager / bundler接收。

免责声明:我是javafx-maven-plugin的维护者和javafx-gradle-plugin

的创建者

编辑更新了处理dpkg-reconfigure的脚本