You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

There is a new maven plugin, maven-bundle-plugin, which we can use in place of custom assembly steps and ant scripts, to build eclipse plugins. There is a way to do the uimaj-ep-runtime plugin so that it works correctly when it is open in the workspace, too. This tip describes the approach and design rationale.

Note: We presume Eclipse 3.2 level as the base. This implies OSGi R4 conventions as the base.

The basic goal is to do things the maven way and reduce custom configuration code in our build, making our build more reliable, understandable, and maintainable over the long run. A second goal is to solve a long-standing problem where the uimaj-ep-runtime plugin, if open in the workspace, made compiling and launching of other plugins that depended on it, not work.

The basic information for how to do this comes from the maven-bundle-plugin documentation: http://felix.apache.org/site/maven-bundle-plugin-bnd.html

This plugin supports "library project" plugins which are just collections of other jars, put into a plugin - exactly what our uimaj-ep-runtime plugin is.

A basic principle is to put all the bundle info that normally would go into the MANIFEST.MF part of the Eclpse plugin into the configuration in the POM for the maven-bundle-plugin, and use that to generate the manifest.mf. This gives just one place to maintain this information. The plugin.xml (used to describe extension points) is still needed if the plugin defines extension points. Some plugins have "blank" plugin.xml - these can just be deleted. The build.properties file is not used, either. (it is used only for Eclipse building the plugins, and we instead have Maven do that).

What does the maven-bundle-plugin do?

It builds the actual plugin jar file. Along the way, takes the information in the POM and uses it to construct the MANIFEST.MF file; we arrange to have this file in the spot where Eclipse PDE expects it, so the plugin can be developed in Eclipse.

Some details:

  • The POM dependencies are used when maven compiles the code for the plugin, and are used by the bundling to find dependencies and do the right "imports" for them in the generated manifest.
  • The configuration for the bundle plugin is where the specifics of what goes into the plugin, what gets exported, what needs to be imported, are specified.
  • Any additional things that need to go into the resulting manifest.mf to support the Eclipse plugin can be put in the POM as configuration specs for the bundle plugin; it will pass these along.

The uimaj-ep-runtime plugin - a special case

This is a library plugin, consisting of jars from other projects. It is built using the maven-bundle-plugin capabilities to specify what packages to export, using the <_exportcontents> directive. This directive avoids actually including those packages in the bundle as direct classes, (versus using the normal <Export-Package> directive), because a later instruction, <Embed-Dependency>, specifies using the dependency information to embed the Jar files maven builds for those, in the bundle being built. Since the jars already have the packages, we use <_exportcontents> to avoid duplicating these contents.

One thing the bundle plugin does is to follow dependency chains in the things it's including. When the uimaj-adapter-soap was included, the bundle plugin determined this needed the axis jars; these are not however part of our distribution. Because of this, the uimaj-adapter-soap dependency is commented out at this point. It's left in as a comment, in case a user wants to build a version of this with the axis files included.

Making the uimaj-ep-runtime plugin work in Eclipse when open

This plugin has an empty src and empty target/classes because all the source/class files were in other projects, it just was a collector of their Jars. This problem is avoided now by changing other projects that previously <depended> on the runtime plugin to depend instead on the individual components that are in the runtime plugin.

These dependencies allow both maven and Eclipse to compile the source of the plugins.

The bundle will create "uses" clauses for packages from the dependencies that it actually uses. These help insure correct "wiring" of the right versions of classes, in the case where multiple versions are present. For more on this, see http://underlap.blogspot.com/2007/10/osgi-type-safety-and-uses-directive.html

Sometimes additions are needed for <Import-Package>

The Eclipse-built manifests put in Require-Bundle entries for things you list in as bundle dependencies. You can continue to do this, also, using the maven-bundle-plugin because it will just pass thru any instructions that start with capital letters like "Require-Bundle" to the manifest.

However, the default is to not do this, but to put the dependencies at a finer granularity than a bundle, using the "uses-" clause in the Export-Package and Private-Package directives. These are imports that OSGi is free to supply from any bundle that exports them. Of course, in our main use case, there is only one such bundle, and everything should work.

The Import-Package directive is there to allow specifying more details about the particulars of the package you want to import, such as a particular version, or a particular bundle it must come from. Eclipse doesn't use them, and we don't either (at the moment).

Issues

The jcasgen plugin no longer builds, unless you go to the project -> properties -> Java Compiler -> Errors/Warnings and change the setting for Deprecated and Restricted API -> forbidden reference from "Error" to "Warning". I'm guessing that some code here is using old, deprecated things, that might no longer work in Eclipse 3.3.

  • No labels