Eclipse PDE and Maven Bundle Plugin

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.

bildschirmfoto2010-06-19um10-49-191.png

This must be configured in the project‘s pom.xml file. (1) bundle 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)

maven-dependency-plugin unpack-dependencies generate-resources unpack-dependencies org.swinglabs,org.jdesktop,com.sun copy-dependencies process-sources copy-dependencies ${basedir} false false true

(3) Add a Maven clean plugin to remove those copied dependencies

maven-clean-plugin 2.3 ${basedir} *.jar false

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

org.apache.felix maven-bundle-plugin true . <_include>META-INF/MANIFEST.MF</_include>

.classpath

Classpath entries such as the following are created to link to the Maven dependencies:

.project

A comment is added to the project description

NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.

(for me it seemed to work fine with eclipse iam.

and a number of linked resources

javaws-1.0.jar 1 /Users/mx/.m2/repository/com/sun/javaws/1.0/javaws-1.0.jar beansbinding-1.2.1.jar 1 /Users/mx/.m2/repository/org/jdesktop/beansbinding/1.2.1/beansbinding-1.2.1.jar swing-worker-1.1.jar 1 /Users/mx/.m2/repository/org/swinglabs/swing-worker/1.1/swing-worker-1.1.jar

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.

Categories: java