question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sling Models are not working if Model classes are inside subfolders.

See original GitHub issue

With Archtype 20, Maven classes are not getting resolved as type inside model’s subfolders if Sling-Model-Packages: com.myapp.core.models is defined in bnd-maven-plugin e.g. com.myapp.core.models.sub

<plugin>
                <groupId>biz.aQute.bnd</groupId>
                <artifactId>bnd-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>bnd-process</id>
                        <goals>
                            <goal>bnd-process</goal>
                        </goals>
                        <configuration>
                            <bnd><![CDATA[
Bundle-Category: MyApp
-exportcontents: ${packages;VERSIONED}
Sling-Model-Packages: com.myapp.core.models
-snapshot: ${tstamp;yyyyMMddHHmmssSSS}
Bundle-DocURL:
                                ]]></bnd>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

We get following error, if we use create model inside subfolder: com.myapp.core.models.sub.HelloWorldModel cannot be resolved to a type

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
arunpatidar02commented, Aug 25, 2019

I dig more into the issue and found that the packages/sub packages apart from default packages are not getting added in Export-Package header in MANIFEST.MF file. All the new packages are getting added in Private-Package header, because of missing package-info.java file in sub/new packages.

To resolve above issue either you can create package-info.java with with version annotation or update core pom to remove VERSIONED filter from -exportcontents.

<plugin>
                <groupId>biz.aQute.bnd</groupId>
                <artifactId>bnd-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>bnd-process</id>
                        <goals>
                            <goal>bnd-process</goal>
                        </goals>
                        <configuration>
                            <bnd><![CDATA[
Bundle-Category: MyApp
-exportcontents: ${packages;}
Sling-Model-Packages: com.myapp.core.models
-snapshot: ${tstamp;yyyyMMddHHmmssSSS}
Bundle-DocURL:
                                ]]></bnd>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
0reactions
Jdruwecommented, Oct 12, 2021

I’ve added the package-info in my sub folder and it got resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

If your Sling Models are not working.....
You need to have: org.apache.sling.models.api.1-1.0.jar installed in the OSGI console, system/console/bundles.
Read more >
Sling Models - Apache Sling
Many Sling projects want to be able to create model objects - POJOs which are automatically mapped from Sling objects, typically resources, ...
Read more >
The Distributed Hydrology Soil Vegetation Model (DHSVM)
The model requires spatially distributed input in the form of surface ... file to the directory where you are storing materials for the...
Read more >
Files & Folders - Help Website - Web Community Manager
Refreshing a subfolder displays a current view of the Files & Folders window. This can be useful if multiple editors are working in...
Read more >
PMP Evaluation Tool Description and Usage
Similar to a shapefile but specific to the ArcGIS environment. Feature classes must be stored within a Geodatabase or Feature. Dataset. 7. Feature...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found