简体   繁体   中英

Java Web Start ExtensionInstallerService - How to get hold of the install path in the application?

Java Web Start features a ExtensionInstallerService that is invoked when the application is installed (and uninstalled). It allows to install "extensions" in a local directory which is provided by the getInstallPath() API which reads like this:

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.

I'd now like to know how to get hold of the provided install path in the running Web Start application (what's defined in application-desc JNLP element).

I've already checked the system properties of the JVM the application is running in. Lot's of deployment.* properties there, but not the install path used by the extension installer. The ExtensionInstallerService itself is unavailable in the running application - so not possible to call getInstallPath() there.

Use ServiceManager.lookup("javax.jnlp.ExtensionInstallerService") to get access to an instance of the service, then use its methods as needed.

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 .

Edit

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 ).

Huh, had not realised. In any case, while in the extension installer code, offer the user the place to install the extension, then store that path using the PersistenceService .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM