2016-03-06 102 views
1

我正在使用Oracle「自包含應用程序打包」工具爲JavaFX 8桌面應用程序生成.deb文件。生成的軟件包文件可以在Ubuntu上安裝而不會出現問題,但是應用程序無法運行。該文件的安裝步驟如下:沒有JRE的JavaFX DEB軟件包不起作用

$ 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

這可能是同樣的事情,在[我的問題](http://stackoverflow.com/questions/32795309/linux-executable-fails-using-javafx-maven-plugin)。另請參閱https://bugs.openjdk.java.net/browse/JDK-8143314和https://bugs.openjdk.java.net/browse/JDK-8143934中的兩個錯誤報告。後者應該用8u76解決。 – hotzst

+0

嗨@hotzst。感謝問題的鏈接。當然,它看起來相關,因爲錯誤消息是相似的。在閱讀你的答案後,我不清楚你做了什麼來解決問題。你能建議我如何應用你所做的來解決這個問題嗎? – Adam

+0

第一步是確定問題是否與可執行jar或啓動程序。要做到這一點,用'java -jar ...'執行jar文件。如果它是啓動器,它可能與配置有關。在我的情況下,cfg文件無法解析,因爲它是從包含'.'的應用程序名稱計算出來的。 Linux可執行文件不要求特定的文件後綴可執行,Windows可以。 – hotzst

回答

1

要在這裏回答這個問題,您需要將JRE_HOME設置爲運行某些本機JavaFX啓動程序,而不捆綁JRE。在Windows上,它在註冊表中查找並搜索HKLM\Software\JavaSoft\Java Runtime Environment\[CurrentVersion]\JavaHome我找不到任何關於此的文檔。

要解決這一點,你需要「更新」的app.runtime - 值作爲postinst -script的一部分,同時安裝執行。事情是這樣的:

#!/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的插件或JavaFX的gradle這個-插件,把這個劇本里面src/main/deploy/package/linux與文件名postinst由javapackager /捆紮機得到回升。

免責聲明:我是javafx-maven-pluginjavafx-gradle-plugin

編輯的維護者和創作者:更新腳本上dpkg-reconfigure工作太