Compilation errors when trying to use sling model in my html | Community
Skip to main content
August 12, 2024
Solved

Compilation errors when trying to use sling model in my html

  • August 12, 2024
  • 4 replies
  • 1687 views

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;

}
Best answer by narendiran_ravi

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;

 

4 replies

MukeshYadav_
Community Advisor
Community Advisor
August 12, 2024
DPrakashRaj
Community Advisor
Community Advisor
August 12, 2024

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
sherinregi-1
Community Advisor
Community Advisor
August 13, 2024

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>
narendiran_ravi
narendiran_raviAccepted solution
Level 6
August 13, 2024

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;

 

ZendarkAuthor
August 14, 2024

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