felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Kriens <Peter.Kri...@aQute.biz>
Subject Re: Bundle plugin: Importing packages from non-bundles
Date Mon, 04 Dec 2006 06:54:39 GMT
The manifest looks fine, there seems to be no bundle exporting the
org.apache.commons.logging package.

BTW, I think the way things are working is slightly different than you
say, it is less automated than you hope :-( You must first decided how
you want to package your bundles, what functionality goes into what

The advantage of the new plugin is that it allows you to compose your
plugin from different sources, not just from your project's src
directory like the old one. That is, the same packages can end up in
multiple bundles. This composition DOES require some design effort.

The Private-Package and Export-Package instructions match regular
expressions to each package on the classpath and if they match a
package, the package goes into the jar. Additionally, you can include
resources from anywhere (with renaming and preprocessing) with the
Include-Resource instruction.

After that, the classes are analyzed for their references to other
classes. This is then used to create the Import-Package header.

If you use a lot of standard JARs you run into the problem that the
fan out of many JARs is enormous. I.e., you use  X and drag in
Y,Z,A,B,C, which each drag in their own dependencies. Unfortunately,
there is no automatic way to decide which dependencies are mandatory
(you REALLY use them) and which dependencies are not intended to be
used. You will have to make a choice.

An easy way to get the bundle installed is use

   Import-Package: *;resolution:=optional

Or instead

   DynamicImport-Package: *

This will make the packages optional and the framework will install
them. However, this is overly broad because it makes all dependencies
optional so you get runtime exceptions when you try to use a class.
You can of course make this more fine grained:

   Import-Package: com.notreallynneed.p; resolution:=optional, *

The bnd utility (http://www.aqute.biz/Code/Download) can also be used
from the command line. It has a print function that shows the imports
and exports from a jar in a convenient for:

    java -jar bnd.jar print -impexp xyz.jar

You can also print the manifest and contents so you do not have to
extract it.

Alas, bundle design requires work because so many JARs have been
filled without regard for minimal coupling. This is why it is so
important to get a commons for bundles. If you have suggestions for
improving the plugin/bnd then please let me know.

Hope this helps, kind regards,

     Peter Kriens

EE> Hi,

EE> I'm having some trouble getting the Maven bundle plugin to do what I
EE> want. I'm new to this OSGi stuff so maybe the problem is what I think
EE> I want, not what the bundle doesn't do. Feel free to enlighten me.

EE> I'm assembling an application consisting of a small number (<5) of
EE> bundles, all of which I own. My bundles are coarse-grained and depend
EE> on a bunch of supporting library files (plain jars, not bundles) in
EE> addition to some of the other bundles.

EE> From what I understand, what we want the plugin to do is to analyze my
EE> source code for real dependencies (e.g. concrete imports in the Java
EE> files) and then for each dependency:

EE>    o figure out the jar declared in the POM that provides the dependency;
EE>    o if that jar file is a bundle, add a proper Import-Package or
EE> Require-Bundle to the OSGi manifest,
EE>    o else if that jar file is just a plain ole jar (and not declared
EE> with scope "provided"), embed it in the bundle and add the jar to
EE> Bundle-Classpath.

EE> Am I completely off here? This seems to be the intuitive and
EE> integrated way to work with Maven and OSGi in harmony. Is there any
EE> way to get this behavior? All our attempts end up with way too much
EE> Import-Packages, few embedded jars and a whole bunch of unresolved
EE> dependency exceptions at runtime.

EE> To clarify, here are some snippets from a bundle with one class (an
EE> Activator) that uses one external class (a commons logger) from one
EE> supporting library (commons-logging-1.1.jar):

--- >>8 --- Activator.java --- >8 ---
EE> package com.organisation.somebundle;
EE> ...
EE> import org.apache.commons.logging.Log;
EE> ...
EE> public class Activator implements BundleActivator
EE> {
EE> ...
EE>         public void start(BundleContext context) throws Exception
EE>         {
EE>                 logger.debug( "Starting somebundle" ); // logger is a commons Log
EE>         }
EE> ...
--- >>8 --- end Activator --- >8 ---

--- >>8 --- pom.xml --- >8 ---
EE> <project>
EE> ...
EE>         <dependencies>
EE>                 <dependency>
EE>                         <groupId>org.osgi</groupId>
EE>                         <artifactId>osgi_R4_core</artifactId>
EE>                         <version>1.0</version>
EE>                         <scope>provided</scope>
EE>                 </dependency>
EE>                 <dependency>
EE>                         <groupId>commons-logging</groupId>
EE>                         <artifactId>commons-logging</artifactId>
EE>                         <version>1.1</version>
EE>                         <type>jar</type>
EE>                 </dependency>
EE>         </dependencies>
EE>         <build>
EE>                 <plugins>
EE>                         <plugin>
EE>                                 <groupId>org.apache.felix</groupId>
EE> <artifactId>maven-bundle-plugin</artifactId>
EE>                                 <extensions>true</extensions>
EE>                                 <version>0.8.0-SNAPSHOT</version>
EE>                                 <configuration>
EE>                                         <instructions>           
EE> <Export-Package>com.organisation.somebundle</Export-Package>
EE>                                         </instructions>
EE>                                 </configuration>
EE>                         </plugin>
EE>                 </plugins>
EE>         </build>
EE> </project>
--- >>8 --- end pom --- >8 ---

--- >>8 --- Bundle manifest --- >8 ---
EE> Manifest-Version: 1

EE> Bundle-Name: Unnamed - com.organisation.somebundle:my-app:bundle:0.1

EE> Created-By: Bnd-0.0.105

EE> Import-Package: com.organisation.somebundle, org.apache.commons.loggin

EE>  g, org.osgi.framework

EE> Bundle-ManifestVersion: 2

EE> Bundle-SymbolicName: com.organisation.somebundle.my-app

EE> Include-Resource: src/main/resources/

EE> Export-Package: com.organisation.somebundle;uses:="org.osgi.framework,

EE>  org.apache.commons.logging"

EE> Bundle-Version: 0.1

--- >>8 --- end manifest --- >8 ---

--- >>8 --- Failing the runtime dependency check --- >8 ---
framework>> install -s file:jars/my-app-0.1.jar
EE> Installed: Unnamed -
EE> com.organisation.somebundle:my-app:bundle:0.1 (#10)
EE> Couldn't install/start bundle: file:jars/my-app-0.1.jar (due to:
EE> org.osgi.framework.BundleException: Failed, missing package(s) or can
EE> not resolve all of the them: org.apache.commons.logging)
EE> org.osgi.framework.BundleException: Failed, missing package(s) or can
EE> not resolve all of the them: org.apache.commons.logging
EE>         at
EE> org.knopflerfish.framework.BundleImpl.start(BundleImpl.java:313)
EE>         at
EE> org.knopflerfish.bundle.frameworkcommands.FrameworkCommandGroup.cmdInstall(FrameworkCommandGroup.java:844)
EE>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
EE>         at
EE> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
EE>         at
EE> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
EE>         at java.lang.reflect.Method.invoke(Method.java:585)
EE>         at
EE> org.knopflerfish.service.console.CommandGroupAdapter.execute(CommandGroupAdapter.java:244)
EE>         at
EE> org.knopflerfish.bundle.console.Command$2.run(Command.java:233)
EE>         at java.security.AccessController.doPrivileged(Native Method)
EE>         at
EE> org.knopflerfish.bundle.console.Command.run(Command.java:220)
EE>         at java.lang.Thread.run(Thread.java:595)
--- >>8 --- end runtime behavior --- >8 ---



Peter Kriens                              Tel +33467542167
9C, Avenue St. Drézéry                    AOL,Yahoo: pkriens
34160 Beaulieu, France                    ICQ 255570717
Skype pkriens                             Fax +1 8153772599

View raw message