Leverage Eclipse to Create Executable OSGi based Applications
Both eclipse and the Netbeans IDE provide strong tool support for deploying applications based on their respective platforms. This includes supports for branding for instance with custom splash screens as well as creating executables for various platforms (Windows, Mac OS X, Linux).
Eclipse allows to define Product configurations, which can be used to export eclipse RCP applications. However, the same mechanism can be used to deploy generic applications composed of OSGi bundles; including, for instance, OSGi applications based on Swing.
The following gives a number of pointers how the eclipse export function can be used to generate an executable of an application consistent of OSGi bundles organized as Maven artifacts.
- Right click on the module, which manages your application life cycle and add a new Eclipse Product configuration.
- Define ID, Version and Navme of the product.
- Under Product Definition, empty Product and Application
- In order to export the application, you might need to download the Eclipse Delta Pack. However, in my case the delta pack for Helios (3.6.1) did not seem to work very well and I had to download launchers individually.
- Add the following dependency to your project:
<dependency> <groupId>org.eclipse.equinox</groupId> <artifactId>app</artifactId> <version>1.0.0-v20070606</version> </dependency> |
- Implement a class as the following:
import org.eclipse.equinox.app.IApplicationContext;
public class LinnkEclipseApplication implements org.eclipse.equinox.app.IApplication {
@Override public Object start(IApplicationContext context) throws Exception { return null; }
@Override public void stop() {
}
} |
(I used this class as ID for the application in the configuration but not sure if that has any implications)
- Under Dependencies, add the bundle, which manages your application lifecycle. Then, click Add Required Plug-Ins. (Do not add other bundles of the platform)
- Under Configuration, make sure that your main bundle is on auto start. If you use Declarative Services, also the *.equinox.ds bundle should be on auto-start.
- From the Overview page you can export your project. The export will generate executables for the platforms you have selected (eg eclipse.exe) with a preconfigured eclipse.ini and a plugins directory with the dependencies of your project.
- With module dependencies declared in Maven, I found that these are often not assembled correctly into osgi bundles from the eclipse product export function. Therefore, I took the 'raw' Maven artifacts and replaced the bundles created by eclipse with them. As the naming conventions of Maven and OSGi are slightly different, I wrote the following crude routine to rename the Macen artifacts.
package de.mxro.zz.mavenosgibundlerenamer;
import java.io.File;
public class BundleRenamer {
public static void main(String[] args) {
File file= new java.io.File("C:/Data/Jars");
for (File f : file.listFiles()) {
String jarName = f.getName(); String bundleName = jarName.replaceFirst("-", "_").replaceFirst("-", ".");
f.renameTo(new File(bundleName));
System.out.println("Jar : "+f); System.out.println("Renamed to: "+bundleName);
}
}
} |
- If you want to get rid of the console window started by eclipse, just remove the Program Arguments from the tab 'Launching'.
Screenshots
Resources
Info on Interfaces to create custom Eclipse application (Eclipse documentation)
Eclipse PDE Tutorial from vogolla.de
Eclipse help pages for product export
How to create an Eclipse product (on eclipse wiki)
Eclipse Downloads – download the delta pack from here
Download the individual launchers from this location (only for Helios 3.6.1)