Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: bnd Import-Package
hi team ,
i'm working on a service builder and for many dev reasons i neet to import some packages like ,
- com.liferay.portal.kernel
- org.osgi.framework
- com.liferay.portal.kernel.exception
..... etc
so I added the dependencies to build. grade, my project has been compiled successfully, but it's not deployed, and after some search I find that I need to import the packages in my bnd. bnd and it works!
so my question is : there is any way to make it work without adding the packages to bnd.bnd / Import-Package cuz my liste of packages become very long , and i'm wondering if there is any good solution for that
Hi Omar,
Sadly, sometimes it is a necessary evil. I guess you could call it one of the "downsides" of OSGI. I have in the past used an inverted scenario where I specify the package NOT to include, rather than the ones to include -- maybe that would help?
With all that said, I am not sure why you aer needingto import the com.liferay.portal.kernel. Those classes are already exported and available in the OSGI container. Can you share you code with us and maybe a little more detail around what you are doing? Perhaps we can offer an alternative that doesn't require the import.
Also -- I am assuming this is for 7.0? (or is it 7.1?)
hi Andrew,
thanks for replying , i'm working on a plugin (for liferay 7.1 CE/DXP ) that forward Audit Messages to a Splunk Server , this the code https://github.com/Ajizan/liferay-splunk
and the bnd.bnd file https://github.com/Ajizan/liferay-splunk/blob/master/liferay-splunk-service/bnd.bnd
:)
Omar, most (all?) of the packages you've listed in your
Import-Package header are redundant. Usually, you only need to list
packages if their code is loaded by reflection (using
Class.forName
or similar); bnd will automatically add any
packages loaded through import
statements, unless you
override that behaviour (as you've done).
From comparing your bnd.bnd with one of mine, my guess is that
javax.net.ssl
, javax.xml.parsers
, and
org.xml.sax
are the only packages that need to be listed
in Import-Package. Add those, and end the list with *
so
bnd will generate the remainder:
Import-Package: \ javax.net.ssl,\ javax.xml.parsers,\ org.xml.sax,\ *
If you add that and still have bundle resolution errors at runtime,
you may need to add some more packages. Make sure to keep the *
.
Hi Omar,
I am 100% inline with Patrick's comment. I have a couple doizen service builder modules across various projects and I have never had to import the kernel dependencies (in 7.1 or in 7.0 for that matter). I did have a similar issue recently and the solutionf or me was just as Patrick said, using the Import-Package statement in the BND and _NOT FORGETTING TO ADD_ the * at the end. I had forgotten that very important part which made a mess during deployment and I had piles of "NoClassDefFound" exceptions showing up in my log.
Powered by Liferay™