Results 1 to 6 of 6

Thread: Spring configuration and imported packages in OSGi bundle

  1. #1
    Join Date
    Jan 2008
    Posts
    9

    Default Spring configuration and imported packages in OSGi bundle

    I am using OSGi and spring dm for a project.
    I use maven and the felix plugin to generate the manifest information.

    In my code I only use interfaces (defined, let's say, in com.acme.bar.api); the implementation of the classes are defined in the spring configuration file (defined, let's say, in com.acme.bar.impl).
    Here is my problem:
    when I generate the manifest info using the felix plugin in the list of imported packages I don't see the ones where my implementation classes are defined. Basically in the list I get com.acme.bar.api, but not com.acme.bar.impl.

    Although it is not practical in the long term, as a workaround I tried to manually add the package in the Import-Package configuration element of the maven-bundle-plugin:

    <Import-Package>*,com.acme.bar.impl*</Import-Package>

    When I run it now I get a warning:

    "Warning building bundle com.acme.foo:foo-impl:bundle:1.0.0-SNAPSHOT : Did not find matching referal for com.acme.bar.impl.*"

    The real problem is that, beside the warning, the package is not actually included in the list of imported packages.

    Two questions :-)

    1. How do I get the maven-bundle-plugin to accept extra packages, even if it cannot find them as imports in the java files?

    2. Is spring dm going to address this problem? In bigger applications it will be pretty tedious to add all the packages that are referenced in the configuration manually!

    Thanks for your help.
    -rico

  2. #2
    Join Date
    Jan 2008
    Posts
    9

    Default

    Ok, I got question n. 1 figured out. In case someone else has the same problem...
    The problem is that I was using the wildcard '*'.
    Adding the package name without the wildcard works.

    I guess that makes sense, as bnd cannot figure out what packages I am talking about when I specify wildcards.

    Any idea regarding question n. 2? How do I tell the maven plugin to add the classes declared in the spring configuration to the Import-Package manifest attribute?

    -rico

  3. #3
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Rico, first of all congratulations of being the first poster on Spring-DM forum and the first person to given an answer .

    For 1 note that you could also used exclusions by using ! - for example "!*.impl, *" results in impl packages being excluded while other packages being included.
    Order does matter.

    As for the second question, no, Spring-DM will not address this problem. Creating manifests is a tooling not a framework problem. Spring-DM handles runtime problems rather then generation of manifests at build time.
    I recommend you see the maven bundle plugin page :
    http://felix.apache.org/site/maven-b...lugin-bnd.html
    Additionally, this blog entry (http://blog.springsource.com/main/20...-osgi-bundles/) might give provide additional insight.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  4. #4
    Join Date
    Sep 2005
    Posts
    26

    Default

    Quote Originally Posted by rico View Post
    Any idea regarding question n. 2? How do I tell the maven plugin to add the classes declared in the spring configuration to the Import-Package manifest attribute?

    -rico
    Rico,

    As I recall, a couple of months ago, Peter Kriens (bnd father integrated into bnd some code from Andy Piper (commiter in Spring DM), code that was meant to kind of parse the spring configuration files, in order to consider whatever classes are declared for Import-Package (your need). I recall that there were some problems with it and (I guess) the support was dropped at least for the time being. I guess you can find out Peters email and write to him directly, asking about the plans regarding this subject.

    Alin Dreghiciu
    Jayway Malaysia

    PS. don;t forget to post his answer

  5. #5
    Join Date
    Jan 2008
    Posts
    9

    Default

    Thanks for the answers.
    Digging into the source code of bnd I saw called plugins, one of which is the spring one (aQute.lib.spring.SpringComponent). The reference to the plugin is commented out in the processor (aQute.lib.osgi.Processor). I guess this must be due to the problems Alin mentioned in his message.
    It is possible to tell bnd to use a plugin by passing a directive. Directives start with a "-" sign, in our case -plugin. As this is not a valid xml tag name, I was trying to figure out how to do that through the maven-bundle-plugin.
    I couldn't find documentation anywhere, but by looking at the source code of the maven-bundle-plugin I saw that:

    <_plugin>aQute.lib.spring.SpringComponent</_plugin>

    should become a -plugin directive for bnd.
    Unforturnately I didn't get that working yet and I am still figuring this out.

    I am posting this info mostly because I couldn't find it anywhere else, so just in case it might be helpful to someone in the future :-)
    I will try to get in touch with Peter... I will keep you posted.

  6. #6
    Join Date
    Jan 2008
    Posts
    9

    Default

    Just wanted to follow up in case someone was having the same issues. This configuration worked for me:

    Code:
      <properties>
        <!-- BND plugin class name(s) -->
        <bnd.plugins>com.acme.bnd.myextension.MyExtensionAnalyzer, aQute.lib.spring.SpringComponent</bnd.plugins>
      </properties>
    
        <plugins>
          <!-- OSGi Felix bundle plugin -->
          <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>1.4.0</version>
            <configuration>
              <instructions>
                <!-- bundle specific conf -->
                <Bundle-Name>${artifactId}</Bundle-Name>
                <Bundle-SymbolicName>com.acme.bundle</Bundle-SymbolicName>
                <Export-Package>com.acme.bundle*</Export-Package>
                <Import-Package>*</Import-Package>
                <Private-Package></Private-Package>
                <!-- jar entries -->
                <Implementation-Title>${pom.title}</Implementation-Title>
                <Implementation-Version>${pom.version}</Implementation-Version>
                <Implementation-Vendor>Acme</Implementation-Vendor>
                <Implementation-Vendor-Id>com.acme</Implementation-Vendor-Id>
                <!-- Spring specific entries -->
                <Spring-DM-Version>1.1.0-m2</Spring-DM-Version>
                <Spring-Version>2.5.4.A</Spring-Version>
                <_plugin>${bnd.plugins}</_plugin>
              </instructions>
            </configuration>
            <extensions>true</extensions>
            <dependencies>
              <dependency>
                <groupId>com.acme.bnd</groupId>
                <artifactId>acme-bnd-lib</artifactId>
                <version>1.0.0</version>
              </dependency>
            </dependencies>
          </plugin>
    This configuration allows me to add my custom plugins to bnd and process the spring files to get the packages added to the bundle's manifest.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •