Java Web Start ExtensionInstallerService - 如何获取应用程序中的安装路径?

标签 java java-web-start jnlp

Java Web Start 具有 ExtensionInstallerService安装(和卸载)应用程序时调用。它允许在本地目录中安装“扩展”,该目录由 getInstallPath() API 提供,如下所示:

java.lang.String getInstallPath()

Returns the directory where the installer is recommended to install the extension in. It is not required that the installer install in this directory, this is merely a suggested path.

我现在想知道如何获取正在运行的 Web Start 应用程序中提供的安装路径(在 application-desc JNLP 元素中定义的内容)。

我已经检查了应用程序运行所在的 JVM 的系统属性。其中有很多 deployment.* 属性,但没有检查扩展安装程序使用的安装路径。 ExtensionInstallerService 本身在正在运行的应用程序中不可用 - 因此无法在那里调用 getInstallPath()

最佳答案

使用ServiceManager.lookup("javax.jnlp.ExtensionInstallerService")访问服务的实例,然后根据需要使用其方法。

Asks the JNLP Client for a service with a given name. The lookup must be idempotent, that is return the same object for each invocation with the same name.

Parameters:

name - Name of service to lookup.

Returns:

An object implementing the service. null will never be returned. Instead an exception will be thrown.

Throws:

UnavailableServiceException - if the service is not available, or if name is null.

编辑

I have no problem to lookup ExtensionInstallerService in the extension installer class (JNLP element installer-desc), but this service is unavailable in the running application (JNLP element application-desc).

呵呵,没想到。无论如何,在扩展安装程序代码中,为用户提供安装扩展的位置,然后使用 PersistenceService 存储该路径。 .

关于Java Web Start ExtensionInstallerService - 如何获取应用程序中的安装路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39623582/

相关文章:

Java 8 RECV TLSv1.2 警报 : fatal, 握手失败

java - 无法将jsonarray导入到eclipse中的jsp中

java - 错误的 hibernate 列类型 : Found: undefined

java - 如何使用 Java 运行 jnlp 文件?

java - 创建Java虚拟机失败

java - 在 tcp 连接中... Java(数据包)

java.util.zip.ZipException : duplicate entry: META_INF/LICENSE. txt

java - HttpsURLConnection 显示安全警告对话框而不是捕获异常

java - Java Web Start 使用什么端口?

Java Web Start 资源 jar 已跳过 future 过期更新检查