Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Export packages are missing in Manifest.MF Header

Avatar

Level 4

Hi Everyone - I am using maven-bundle-plugin artifact in the core module. The issue I am facing is sling model not available, I found that Export Package header in the bundle MANIFEST.MF section is empty which causes the issues with the sling models.

I have also tried with "bnd-maven-plugin" artifactId and removed the VERSIONED filter from -exportcontents but it is still not generating. I have already tried with updating the Manifest.MF manually and it worked, so the issue is only related to Export Package header. Can someone suggest on this issue?

 

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>4.1.0</version>
<inherited>true</inherited>
<configuration>
<instructions>
<!--<Embed-Dependency>org.apache.servicemix.bundles.aws-java-sdk, netty-all</Embed-Dependency>
--><!-- Import any version of javax.inject, to allow running on multiple
versions of AEM -->
<Import-Package>javax.inject;version=0.0.0,*</Import-Package>
<Sling-Model-Packages>
com.test.aem.abc.core.xyz.impl.models
</Sling-Model-Packages>
</instructions>
</configuration>
</plugin>

@Arun_Patidar

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @s1101v,

Can you share the latest core/pom.xml(in particular, <build> tag details) and package structure of Java classes. 

 

View solution in original post

16 Replies

Avatar

Community Advisor

@s1101v 

Check you package is under Private-Package, in bundle manifest. If so add package info(package-info.java) to your package and see.

Avatar

Level 4
@Anudeep_Garnepudi - I have already added the package-info in my package, I still don't see "Private-Package" section in the bundle. In order to make the model available, the package should be listed in the Private-Package section?

Avatar

Community Advisor
It should not be in Private-Package, it should be in Export-Package

Avatar

Level 4
@Anudeep_Garnepudi - There are two export package section in the bundle header. The one is “Exported Packages” at the top which is empty and another one says “Export-Package” which has the package details which is below Import Package section. Can you tell me what could be the issue even though we have the package-info in all the sub packages.

Avatar

Correct answer by
Community Advisor

Hi @s1101v,

Can you share the latest core/pom.xml(in particular, <build> tag details) and package structure of Java classes. 

 

Avatar

Level 4
@Vijayalakshmi_S - PFB Package Structure: com.company.aem.xyz.core.models -> (Models & Interface) <build> <plugins> <plugin> <groupId>org.apache.sling</groupId> <artifactId>sling-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</extensions> <configuration> <instructions> <Export-Package> com.company.aem.xyz.core.* </Export-Package> <Bundle-SymbolicName>com.company.aem.xyz.core</Bundle-SymbolicName> <Import-Package>javax.inject;version=0.0.0,*</Import-Package> <Sling-Model-Packages> com.company.aem.xyz.core.models </Sling-Model-Packages> </instructions> </configuration> </plugin> <build>

Avatar

Community Advisor
Thanks for sharing the details. Can you remove <Export-Package> and <Bundle-SymbolicName> entry from instructions and lets leave it to handle with defaults and observe the behavior.

Avatar

Level 4
@Vijayalakshmi_S - I am getting the same error after I remove the <Export-Package> and <Bundle-SymbolicName>. org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: Compilation errors in org/apache/sling/scripting/sightly/apps/project/components/structure/page/page_html.java: Line 46, column 2099 : com.company.aem.xyz.core.models.TestPage cannot be resolved to a type

Avatar

Community Advisor

Okie. Given that Sling model is not recognized per the error message, the way the package name/structure is defined inside core module for models family matters. Can you confirm the list of classes/models that resides under com.company.aem.xyz.core.models

Avatar

Level 4
@Vijayalakshmi_S - Under this package - com.company.aem.xyz.core.models, I have kept only the models and their interfaces used in the model.

Avatar

Community Advisor

Can you retain only the interfaces in com.company.aem.xyz.core.models and move the model implementation to something like com.company.aem.xyz.core.internal.model.impl and then,

1. Execute as is or 

2. Remove <Sling-Model-Packages> and use Sling Models bnd plugin to scan the models. Details for the same as below

<_plugin>org.apache.sling.bnd.models.ModelsScannerPlugin</_plugin> within <instructions> tag and dependency information for this plugin within <dependencies> section of build definition.

 

 

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
        <instructions>
            <_plugin>org.apache.sling.bnd.models.ModelsScannerPlugin</_plugin>
        </instructions>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.bnd.models</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>
</plugin>

 

 

 

Avatar

Level 4
@Vijayalakshmi_S - I have tried with both approaches but the mode is not available and still getting the same error. I have verified in "system/console/status-adapters", I could see only one model which comes under "Available Adapters:" i.e used in the Base Page component. If I check the bundle Manifest Header, I could see all the packages listed in "Export-Package" section. Not sure if I am adding anything wrong here. Can you suggest what could be the issue at this point?

Avatar

Community Advisor

@s1101v,

For Sling Model to be recognized, we use either <Sling-Model-Packages> or Sling Model bnd plugin that I shared in my previous comment

Along with this, package structure that holds the model matters. 

If you have both satisfying correct, you should see your model in Sling Adapters console. 

 

Outside this, Export-Package definition will skip the implementation classes. Example if you would have this package -  com.company.aem.xyz.core.models in Export-Package entry in <instructions> and if files under this package are both interface and implementation, then this would not be part of Exported-Packages  (as you view the bundle in Felix console)

 

Also, I couldn't get your point - "If I check the bundle Manifest Header, I could see all the packages listed in "Export-Package" section" in your latest comment.

Avatar

Level 4
@Vijayalakshmi_S - I was referred about this one. Please find below the Export-Package section: Export-Package: com.company.project.xyz.core.models; version="1.0"; uses:="com.adobe.cq.wcm.core.components.models, org.apache.sling.api.resource", com.company.project.xyz.core.services; version="1.0", com.company.project.xyz.core.util; version="1.0"; uses:="com.day.cq.dam.api, com.company.project.xyz.core.models, org.apache.commons.lang3.tuple, org.apache.sling.api, org.apache.sling.api.resource", com.company.project.xyz.internal.impl.models; version="1.0"; uses:="com.adobe.cq.export.json, com.adobe.cq.wcm.core.components.models, com.company.project.xyz.core.models, javax.annotation, org.apache.sling.api, org.apache.sling.api.resource, org.apache.sling.models.annotations"

Avatar

Community Advisor

Try the following :

  • Have a backup of your project code base ->
  • With respect to models, have only one package named com.company.project.xyz.core.models and write direct model class inside it, say HelloWorldModel that is available as part of AEM Maven archetype project.
  • Remove all your project specific Model related interfaces and implementation.

In core/pom.xml file, let the <Sling-Model-Packages> be this - com.company.project.xyz.core.models or use Sling Model bnd plugin

You need not have explicit Export-Package entry in instructions.

Note : If any other classes are using your model, remove all trace of it. Example I see com.company.project.xyz.core.util is using your model.