RE: bnd Import-Package

omar harrari, modified 6 Years ago. New Member Posts: 5 Join Date: 2/26/18 Recent Posts

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 

thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts

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?)

omar harrari, modified 6 Years ago. New Member Posts: 5 Join Date: 2/26/18 Recent Posts

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 

 

:) 

Patrick Conley, modified 6 Years ago. New Member Posts: 17 Join Date: 7/14/15 Recent Posts

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 *.

thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts

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.