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 isnull
.
编辑
I have no problem to lookup
ExtensionInstallerService
in the extension installer class (JNLP elementinstaller-desc
), but this service is unavailable in the running application (JNLP elementapplication-desc
).
呵呵,没想到。无论如何,在扩展安装程序代码中,为用户提供安装扩展的位置,然后使用 PersistenceService
存储该路径。 .
关于Java Web Start ExtensionInstallerService - 如何获取应用程序中的安装路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39623582/