gpt4 book ai didi

没有 JRE 的 JavaFX DEB 包不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:11:42 25 4
gpt4 key购买 nike

我正在使用 Oracle“Self-Contained Application Packaging”工具为 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 对此进行测试。

最佳答案

要在这里也回答这个问题,您需要将 JRE_HOME 设置为运行一些 native 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 的脚本

关于没有 JRE 的 JavaFX DEB 包不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35826939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com