One of the most difficult issues facing Eclipse RCP developers has been how to consume third-party libraries. We often want to use JAR files not available as OSGi plug-ins (missing OSGi metadata) or that are not available in a p2 repository.
So far, our options have included:
- Accessing a JAR file in Eclipse Orbit. For many years Eclipse committers have been adding metadata to third-party JARs and making them available in a p2 repository (thank you, btw). The problem with this approach is that many libraries are not available, and those that are may not be the desired version.
- Using a PDE wizard to generate an Eclipse Plug-in from one or more JAR files. This works, but it’s ugly and you have to maintain these projects over time, including checking them into your VCS.
Neither of these options has been a good long-term solution for Eclipse RCP developers.
The new Maven target location type
I’m happy to say that Eclipse RCP developers can now directly access all of the libraries available in Maven repositories, whether these libraries contain OSGi metadata or not.
In our Eclipse RCP applications we typically manage our dependencies through target definition files. These files list the repositories and artifacts that our application depends on and compiles with. Basically, this is the Eclipse RCP version of Maven dependencies specified in POMs.
Target definitions are made up of target locations which can be one of four types. For all practical purposes, the only type that really mattered was Software Site, which is a p2 repository location. This is the only target location type available in Maven Tycho builds, so the other location types are not very useful.
Now there is finally a fifth target location type: Maven. This type is honored both inside the Eclipse IDE and also in Tycho builds (versions 2.1 or later)
Installing the Maven location type
The new Maven location type is contributed by the m2e PDE feature. The first step to accessing the location type is to install this feature if it’s not already present.
In your Eclipse IDE, choose Help > Install New Software… Add the update site below and then select the m2e PDE Integration feature.
http://download.eclipse.org/technology/m2e/releases/latest/
Once the feature is installed and you restart Eclipse, you should see the new target location type in the Target Definition Editor.
Using the Maven location type
Selecting the new location type after clicking Add in the Target Definition Editor brings you to a dialog allowing you to enter the Maven GAV coordinates for the JAR.
After completing the dialog, the target will resolve and you should see the JAR (now an OSGi bundle) in your target.
Now you can create dependencies on this new bundle and start using it directly. No more Orbit, no more ugly JAR wrapper projects.
I’d like to thank Christoph Läubrich for doing the work that made this possible. According to this forum post there is still more work that can be done to improve the functionality, and if this matters to your organization please consider providing support!