To get eclipse PDE working hand in hand with Maven is a rather tricky task. I have already written about some necessary tweaks to get it working.
Another way is to use the Apache Felix Maven bundle plugin. This Maven plugin is able to generate the necessary files for the eclipse PDE to work with the Maven files. It does so by copying the JARs that the Maven project depends on and by altering the .classpath and .project files of the project.
I found that this procedure works fine with eclipse projects, which are already linked to eclipse IAM and have been created as eclipse plugin projects.
Copying Maven Dependencies
The Maven dependencies are directly copied to the project‘s main folder. The dependencies are the jars in the following screenshot.
This must be configured in the project‘s pom.xml file.
(1) <packaging>bundle</packaging> must be added
(2) A plugin to copy the dependencies must be added (I added a further execution to unpack the dependencies for reasons described in OSGi: Libraries Requiring Access to Bundle ClassLoader)
(3) Add a Maven clean plugin to remove those copied dependencies
(4) Add a plugin to configure the bundles manifest file. I think the syntax to create these files using the plugin is quite verbose and rather use the PDE tools for generating a bundle. Therefore, the plugin basically just copies the MANIFEST.MF edited with eclipse.
Classpath entries such as the following are created to link to the Maven dependencies:
<classpathentry kind=”lib” path=”beansbinding-1.2.1.jar”/>
<classpathentry kind=”lib” path=”javaws-1.0.jar”/>
<classpathentry kind=”lib” path=”swing-worker-1.1.jar” sourcepath=”/Users/mx/.m2/repository/org/swinglabs/swing-worker/1.1/swing-worker-1.1-sources.jar”>
<attribute value=”jar:file:/Users/mx/.m2/repository/org/swinglabs/swing-worker/1.1/swing-worker-1.1-javadoc.jar!/” name=”javadoc_location”/>
A comment is added to the project description
<comment>NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
(for me it seemed to work fine with eclipse iam.
and a number of linked resources
I am not too happy about the absolute paths used here. These require a different .project file on each workstation. However, the .project file can be fairly easy created with the Maven Bundle Plugin.
mvn clean package eclipse:eclipse -Declipse.pde install
Sometimes it is better to call mvn eclipse:clean clean package eclipse:eclipse -Declipse.pde install as otherwise the classpath is not created correclty.