Firefox 中调用 Oracle JRE javaws 打开 JNLP 文件

WHAT

HP 服务器的 iLO 无法通过 icedtea-web 打开 Java Web Start jnlp文件,只能使用 Oracle JRE 的 javaws 打开。

但在 Firefox 浏览器中找不到 Sun JavaWS 的打开方式,只能通过 命令行 打开 jnlp 文件:

# rpm -Uvh jre-8u281-linux-x64.rpm

# rpm -ql jre1.8 | grep -i javaws
/usr/java/jre1.8.0_281-amd64/bin/javaws
/usr/java/jre1.8.0_281-amd64/lib/desktop/applications/sun-javaws.desktop
/usr/java/jre1.8.0_281-amd64/lib/desktop/icons/HighContrast/16x16/apps/sun-javaws.png
/usr/java/jre1.8.0_281-amd64/lib/desktop/icons/HighContrast/48x48/apps/sun-javaws.png
/usr/java/jre1.8.0_281-amd64/lib/desktop/icons/HighContrastInverse/16x16/apps/sun-javaws.png
/usr/java/jre1.8.0_281-amd64/lib/desktop/icons/HighContrastInverse/48x48/apps/sun-javaws.png
/usr/java/jre1.8.0_281-amd64/lib/desktop/icons/LowContrast/16x16/apps/sun-javaws.png
/usr/java/jre1.8.0_281-amd64/lib/desktop/icons/LowContrast/48x48/apps/sun-javaws.png
/usr/java/jre1.8.0_281-amd64/lib/desktop/icons/hicolor/16x16/apps/sun-javaws.png
/usr/java/jre1.8.0_281-amd64/lib/desktop/icons/hicolor/48x48/apps/sun-javaws.png
/usr/java/jre1.8.0_281-amd64/lib/javaws.jar
/usr/java/jre1.8.0_281-amd64/lib/javaws.pack
/usr/java/jre1.8.0_281-amd64/lib/security/javaws.policy
/usr/java/jre1.8.0_281-amd64/man/ja_JP.UTF-8/man1/javaws.1
/usr/java/jre1.8.0_281-amd64/man/man1/javaws.1

# ls -lh /usr/java/jre$(rpm -q --queryformat "%{VERSION}\n" jre1.8)-amd64/

HOW

软件包自带的 sun-javaws.desktop 文件复制到 /usr/share/applications/ 后浏览器是 无法 识别到打开方式的:

# cat /usr/java/jre1.8.0_281-amd64/lib/desktop/applications/sun-javaws.desktop
#
# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
# Use is subject to license terms.
#
# Desktop entry for the automatic execution of jnlp files identified as
# the x-java-jnlp-file mime type.
#
# Note: This file may be installed under both "control-center-2.0" and
# "applications".  Depending upon the version of GNOME, the copy in
# "applications" may take precedence.
#
[Desktop Entry]
Encoding=UTF-8
Name=JavaWS
Comment=Java Web Start
Exec=javaws
Icon=sun-javaws.png
Terminal=false
Type=Application
NoDisplay=true
Categories=Java;Applications;
MimeType=application/x-java-jnlp-file;

参考 icedtea-webjavaws.desktop 文件创建 sun-javaws.desktop 文件:

# rpm -qf /usr/share/applications/javaws.desktop
icedtea-web-1.7.1-18.el8.noarch

# cat /usr/share/applications/sun-javaws.desktop
[Desktop Entry]
Name=Sun JavaWS
GenericName=Sun Java Web Start
Comment=JNLP Application Launcher
Exec=/usr/java/jre1.8.0_281-amd64/bin/javaws %u
Icon=/usr/java/jre1.8.0_281-amd64/lib/desktop/icons/hicolor/48x48/apps/sun-javaws.png
Terminal=false
Type=Application
NoDisplay=false
Categories=Application;Network;WebBrowser;
MimeType=application/x-java-jnlp-file;x-scheme-handler/jnlp;x-scheme-handler/jnlps
X-Desktop-File-Install-Version=0.23

注意Exec=/usr/java/jre1.8.0_281-amd64/bin/javaws %u 缺少 %u 参数浏览器识别不到打开方式

Desktop files: putting your application in the desktop menus

%u a single URL.

比较一下差异:

# diff javaws.desktop sun-javaws.desktop
[Desktop Entry]                                                 [Desktop Entry]
Name=Sun JavaWS                                               | Name=IcedTea Web Start
GenericName=Sun Java Web Start                                | GenericName=Java Web Start
Comment=JNLP Application Launcher                             | Comment=IcedTea Application Launcher
Exec=/usr/java/jre1.8.0_281-amd64/bin/javaws %u               | Exec=/usr/bin/javaws.itweb %u
Icon=/usr/java/jre1.8.0_281-amd64/lib/desktop/icons/hicolor/4 | Icon=javaws
Terminal=false                                                  Terminal=false
Type=Application                                                Type=Application
NoDisplay=false                                               | NoDisplay=true
Categories=Application;Network;WebBrowser;                    | Categories=Network;WebBrowser;
MimeType=application/x-java-jnlp-file;x-scheme-handler/jnlp;x   MimeType=application/x-java-jnlp-file;x-scheme-handler/jnlp;x
X-Desktop-File-Install-Version=0.23                             X-Desktop-File-Install-Version=0.23

更新 desktop database 数据库:

# update-desktop-database -v /usr/share/applications/

确认 sun-javaws.desktop 成功关联 jnlp 文件:

# grep javaws /usr/share/applications/mimeinfo.cache
application/x-java-jnlp-file=javaws.desktop;sun-javaws.desktop;
x-scheme-handler/jnlp=javaws.desktop;sun-javaws.desktop;
x-scheme-handler/jnlps=javaws.desktop;sun-javaws.desktop;

然后就能在浏览器中找到刚添加的 Sun JavaWS 打开方式:

img

reference

Desktop files: putting your application in the desktop menus

https://wiki.archlinux.org/title/Desktop_entries