Expand my Community achievements bar.

SOLVED

Compilation errors when trying to use sling model in my html

Avatar

Level 2

I have created a new component and when i try to use the sling model using data-sly-use
i get the below error , is there any reason for this error?

org.apache.sling.scripting.sightly.SightlyException: Compilation errors in org/apache/sling/scripting/sightly/apps/myproject/components/content/components/demo__component/demo__002d__component__002e__html.java:
Line 39, column 1932 : com.myproject.core.slingmodels.components.democomponent.DemoComponentModel cannot be resolved to a type

 This is my sling model

package com.myproject.core.slingmodels.components.democomponent;

import com.myproject.core.slingmodels.HeaderModel;
import lombok.Getter;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.ChildResource;


@Getter
@Model(adaptables = Resource.class,
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class DemoComponentModel {

@ChildResource
private HeaderModel Heading;

}
1 Accepted Solution

Avatar

Correct answer by
Level 3

Can you check if the package info file has been added -  this will scan the models 

package-info.java

@Version("1.0")
package com.your.sling.models.yourpackage;
import org.osgi.annotation.versioning.Version;

 

View solution in original post

5 Replies

Avatar

Level 7

Hi @Zendark ,

You may check status of bundle http://localhost:4502/system/console/bundles

 

@Getter can be filed level or use @Data annotation for class level as mentioned below

https://kiransg.com/tag/getter/

You may check here how to use lambok https://experienceleaguecommunities.adobe.com/t5/experience-league-showcase-2022/using-project-lombo...

If issue doesn't resolved you may have a look https://github.com/adobe/aem-project-archetype/issues/221 as your are using sub folder

Thanks

Avatar

Community Advisor

You need to check more entry in logs. It’s actually failing during compilation so it seems it has something to do with your code abd log will give you more insights on this.
What about this class ? Have you defined it properly?

  • HeaderModel

Avatar

Level 9

Hi @Zendark 

Can you please check if you are adding the sling models package in pom as well

<Sling-Model-Packages>com.myproject.core.slingmodels</Sling-Model-Packages>

Avatar

Correct answer by
Level 3

Can you check if the package info file has been added -  this will scan the models 

package-info.java

@Version("1.0")
package com.your.sling.models.yourpackage;
import org.osgi.annotation.versioning.Version;

 

Avatar

Level 2

By adddind this file in my sling model folder , it works thank you