The bundle activator utility class ExecutableBundleActivator can be used if you need to package an executable binary in your bundle that should be extracted and started when the bundle starts.
Depending on your needs you can either write your own bundle activator that extends ExecutableBundleActivator or use it directly without writing any Java code at all. If you use it directly, all you need to do is to add custom headers to your manifest that controls the behavior of ExecutableBundleActivator.
The following are the required headers for a simple example.
Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.knopflerfish.bundle.ebaexample Bundle-Activator: org.knopflerfish.util.framework.ExecutableBundleActivator Import-Package = org.knopflerfish.util.framework,org.osgi.framework Bundle-Start-Executable: notepad.exe ; processor=x86 ; osname=WindowsXP
In this case there is only one custom header, Bundle-Start-Executable. It declares that if the native environment matches OS = Windows XP and processor architecture = x86, the resource named notepad.exe should be extracted from the bundle, written to the local file system and launched using java.lang.Runtime.exec() when the bundle is started.
The exec:ed process will be terminated when the bundle stops. If the process is terminated, the bundle will be stopped (this is the default behavior).
Complete list of custom headers for this utility class:
In many cases you want to write your own activator that extends ExecutableBundleActivator. You can then for example override logging which is on and to stdout by default. Also, you need to write your own activator if you want your bundle to do more than starting a native executable.
Files that are extracted (executables and other resources) are written to the bundle's persistent storage area. Cleanup of the files takes place when the bundle is uninstalled.
Package | Version | Providers |
---|---|---|
org.knopflerfish.util | 1.1.0 | util-4.1.0 |
org.knopflerfish.util.framework | 1.0.0 | util-4.1.0 |
org.knopflerfish.util.sort | 1.0.0 | util-4.1.0 |
org.knopflerfish.util.workerthread | 1.0.0 | util-4.1.0 |