Is there any relationship between the bundles mentioned in the <dependencies>
tag and the <Import-Package>
tag? I mean if we don't define dependency, then maven-bundle-plugin can not find the packages in <Import-Package>
tag?

- 32,010
- 5
- 70
- 103

- 61
- 1
- 6
2 Answers
Maven uses the jars listed in the dependencies section to create a classpath. This class path is used by bnd (the engine in the maven bundle plugin) to analyze what your code is referring to through byte code analysis.
maven dependency -> classpath -> bnd analysis -> import statements

- 15,196
- 1
- 37
- 55
Import-Package
is used to refine the list of package imports which the maven bundle plugin generates automatically for you. For example, you could declare some imports optional, or add imports for classes which are only accessed by reflection. In most cases it shouldn't be necessary to specify anything at all for Import-Package
since the default is *
- that is, any external packages referenced in your bytecode will be imported.
The dependencies
section provides the pool of bundles used by the compiler to generate the bytecode, and bnd (which is what the bundle plugin under the covers) to improve the package imports. For example, it will add version ranges based on the exported versions in a providing bundle in the dependencies list (or in transitive dependencies).

- 75,346
- 28
- 201
- 283

- 10,767
- 3
- 23
- 25
-
but where to find the referenced packages in bytecode automatically? from the local maven repository? – user1450233 Sep 17 '12 at 01:24
-
Once a package is referenced in bytecode, the bundle plugin already knows its name and can include it in the import package statement, so it doesn't need to be "found". However, almost always anything referenced in the bytecode will be included as a maven dependency, because otherwise how could it have been compiled? Dependencies listed in the 'dependencies' section are pulled from local or remote maven repositories. This allows the bundle plugin to work out the version range to import. – Holly Cummins Sep 17 '12 at 04:40