掲示板

Is there any alternative of Import-Package and Private-Package in liferay 7

thumbnail
7年前 に Abhishek Jain によって更新されました。

Is there any alternative of Import-Package and Private-Package in liferay 7

Regular Member 投稿: 226 参加年月日: 16/08/20 最新の投稿
I want to ask if there is any alternative of Import-Package and Private-Package in liferay 7? I am asking this because when I add these lines in the bnd.bnd file I am getting NoClassDefFoundError.. and when I remove these lines, the module executes without error. So please tell the alternatives for the same. Thanks in advance..
thumbnail
7年前 に David H Nebinger によって更新されました。

RE: Is there any alternative of Import-Package and Private-Package in lifer

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
There are no alternatives, but they are there not for general usage but to provide hints to BND.

BND processes the bnd.bnd file you give it along with metadata from the code to build a complete manifest.

However, if you put things into these keys bnd assumes you know what you are doing and, if you don't, you mess things up on your own.

Private-Package is used to hide classes from the OSGi framework. You'll see that a lot of Liferay's portlet classes are being put into packages with "internal" in the package name and internal is usually added to Private-Package with the idea that other bundles in OSGi should not have any visibility on them.

Import-Package is used to identify dependencies that bundle needs to start, but this is something that BND can typically derive on its own. Liferay will sometimes add imports in order to get around case where BND is unable to identify the dependency (for example, BND can identify an import for javax.portlet but it may miss the transitive dependency on javax.servlet, so the import package is used to make sure it is included by BND).

Also you can use Import-Package to exclude packages from transitive dependencies that you really don't need. This typically will be needed if a developer does not correctly mark transitive dependencies as optional in the jar manifest. You'll find this when they have, for example, junit test cases in their code and for their module to build they need junit and they build a simple jar from it, but when you deploy it to OSGi you'll get unresolved references to junit.* so the bundle cannot start. You fix this by using:

Import-Package: !junit,\
  *

But that last piece, the wildcard, is very important. If you leave it out, all you have is the exclusion and BND is going to end up building a bad manifest because you've told it not to include anything at all.

Morale of the story: don't use something just because you see Liferay using it, understand what it is, understand what it does, and understand how to use it correctly once you've decided that you need it.
thumbnail
7年前 に Abhishek Jain によって更新されました。

RE: Is there any alternative of Import-Package and Private-Package in lifer

Regular Member 投稿: 226 参加年月日: 16/08/20 最新の投稿
Thanks David for your valuable response and wonderful information.. emoticon