In Maven, including dependency via <dependency> OR importing the package inside <Import-Package>. Which one of the two should be used?
1. In my project core pom.xml, there is <Import-Package>javax.inject;version=0.0.0<Import-Package> and also following dependency. I am not clear why both are being used? I mean, if we are already including the dependency via below-mentioned method, then why do we need to use the same inside <Import-Package>?
2. Same scenario is happening in my project. My project A is dependent on project B, there also I have noticed that package path has been added in <Import-Package> and dependency has been added for project B in core/pom.xml of Project A. why both? Somebody please clarify this.
Import-Package is for importing available dependencies when the state of osgi bundle is changed during its lifecycle in the container (Felix), Version 0.0.0 indicates that it should start from the lowest version, pick whatever version is available as mentioned in manifest and satisfy the dependency at runtime in Felix.
The packages mentioned here may/may not be available/packaged within the bundle but may be available/registered in Felix
You may choose to control it at a granular level that import * but not one package or something similar to that. import-package is required to create the manifest file properties
Dependency on other hand works with dependency management to download the packages in local repo/nexus etc. and to mark that a particular bundle should be applied at specific scope mentioned inside <scope>. It defines the scopes of dependent bundles and which can again be superseded with import-package configuration to allow/deny the packaging of that bundle
my only point is whatever we include in <import-pakage> tag, Can't we just include a dependency for that tag like below. What is the harm? what is the benefit of <import-pakage> tag providing over a dependency tag?
<import-package>:import packages means including a existing jar. you can include the third party jar using it. suppose you have a another different project (like web service calls) in your complete project. then you can include it using import packages. plugins generates the Import-Package bundle manifest header based on the contents of the bundle.