views:

409

answers:

1

I want to deploy one of my OSGi bundles with a war package structure so it is recognized as a web application by Struts. I use Maven, so I get WAR packaging built-in and I have the Maven bundle-plugin to create the OSGi compatible manifest for me.

The problem is, the two don't work together, so the bundle plugin is not aware that the class files are now in the subfolder classes/ and the bundled jars are in lib/, so it creates a wrong Bundle-classpath header. I could manually add the correct header to my pom.xml, but I'd like to have that don eautomatically. How can I do that?

+1  A: 

One way to (more or less) achieve this is described on OPS4J Wiki page -- "Getting the benefits of maven-bundle-plugin in other project types".

You can configure dependency embedding and Bundle-ClassPath directive in your pom.xml to match the locations used by WAR plugin. The maven-bundle-plugin will then generate correct manifest headers.

The instructions for maven-bundle-plugin might look like this:

<instructions>
    <Bundle-ClassPath>.,WEB-INF/classes,{maven-dependencies}</Bundle-ClassPath>

    <Embed-Directory>WEB-INF/lib</Embed-Directory>
    <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
    <Embed-Transitive>true</Embed-Transitive>
    <!-- ... -->
</instructions>


ETA: When using this approach, I found out two noteworthy things:

  • the bundle plugin will complain about missing WEB-INF directories, because when the manifest goal is executed, the war plugin has not yet created them (it only runs at a later phase)
  • although it doesn't make sense for the actual webapp, the Bundle-ClassPath directive must contain ".", or the bundle plugin will mess up the Import-Packages header. I found this in some JIRA issue via Google, but I can't find the URL anymore.

Other than that it works fine.

Pavol Juhos
+1 for `{maven-dependencies}` (see http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html#ApacheFelixMavenBundlePlugin%28BND%29-Embeddingdependencies)
Pascal Thivent
Great. I sort of knew this but I hadn't seen the `Embed-Directory` directive before.
Hanno Fietz