AEM project app cannot resolve package dependency in core | Community
Skip to main content
April 9, 2020
Solved

AEM project app cannot resolve package dependency in core

  • April 9, 2020
  • 1 reply
  • 4566 views

Hey everyone,

 

I have an AEM project where a utility class is found in the core module and is referenced in the apps module in an asset.jsp overlay. However, whenever I attempt to bring up the page in AEM which uses the overlay I am getting an exception that the overlay could not be compiled because this the module reference class could not be found.

 

Any help would be appreciated.

 

Error Log

==> error.log <==

09.04.2020 00:18:38.206 *ERROR* [0:0:0:0:0:0:0:1 [1586416718199] GET /mnt/overlay/dam/gui/content/assets/jcr:content/views/list.0.40.html/content/dam/site/aem/jobnumber/assetfolder HTTP/1.1] org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught SlingException

org.apache.sling.scripting.jsp.jasper.JasperException: Unable to compile class for JSP:

 

An error occurred at line: 7 in the generated java file

Only a type can be imported. com.site.assets.core.utils.statusutil resolves to a package

at org.apache.sling.scripting.jsp.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:93)

at org.apache.sling.scripting.jsp.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)

at org.apache.sling.scripting.jsp.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:136)

at org.apache.sling.scripting.jsp.jasper.compiler.Compiler.compile(Compiler.java:304)

at org.apache.sling.scripting.jsp.jasper.compiler.Compiler.compile(Compiler.java:282)

at org.apache.sling.scripting.jsp.jasper.compiler.Compiler.compile(Compiler.java:269)

at org.apache.sling.scripting.jsp.jasper.JspCompilationContext.compile(JspCompilationContext.java:501)

at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.prepareServlet(JspServletWrapper.java:427)

at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:486)

at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:449)

at org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:346)

at org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:101)

 

site.core POM

<plugins>
<plugin>
<groupId>org.apache.sling</groupId>
<artifactId>maven-sling-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>!com.csvreader.*,javax.inject;version=0.0.0,*</Import-Package>
<Sling-Model-Packages>
com.site.assets.core
</Sling-Model-Packages>
</instructions>
</configuration>
</plugin>
</plugins> 

 

asset.jsp Imports

<%@page import="org.apache.sling.api.resource.Resource"%>
<%@page import="com.site.assets.core.utils.statusutil"%>
<%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0"%>
<%@include file="/libs/dam/gui/coral/components/admin/contentrenderer/base/init/assetBase.jsp"%>
<%@include file="/libs/dam/gui/coral/components/admin/contentrenderer/base/insightBase.jsp"%>
<%@include file="/libs/dam/gui/coral/components/admin/contentrenderer/row/common/common.jsp"%>

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Theo_Pendle

Hi,

The error seems quite informative to me: 

Only a type can be imported. com.site.assets.core.utils.statusutil resolves to a package

So what are you trying to import exactly?

  1. If com.site.assets.core.utils.statusutil is meant to be a class then:
    1. Make sure it actually is a class
    2. Change the name to reflect that fact (should be StatsUtil not statsutil)

  2. If com.site.assets.core.utils.statusutil is a package then:
    1. Fix the import to import the class in question (eg: com.site.assets.core.utils.statusutil.StatsUtil)
    2. Fix the import to import all classes in the package (eg. com.site.assets.core.utils.statusutil.*)

Also, make sure thal all your packages include a package-info.java file.

1 reply

Theo_Pendle
Theo_PendleAccepted solution
April 9, 2020

Hi,

The error seems quite informative to me: 

Only a type can be imported. com.site.assets.core.utils.statusutil resolves to a package

So what are you trying to import exactly?

  1. If com.site.assets.core.utils.statusutil is meant to be a class then:
    1. Make sure it actually is a class
    2. Change the name to reflect that fact (should be StatsUtil not statsutil)

  2. If com.site.assets.core.utils.statusutil is a package then:
    1. Fix the import to import the class in question (eg: com.site.assets.core.utils.statusutil.StatsUtil)
    2. Fix the import to import all classes in the package (eg. com.site.assets.core.utils.statusutil.*)

Also, make sure thal all your packages include a package-info.java file.

pa_dcAuthor
April 13, 2020

Overall, the naming is specifically for posting the question on the forum. In the project it is named with the casing you specified in your comment.

 

I have tried the solutions you specified but by the time I attempt to use the class it says the same message of not being able to resolve the dependency and resolving to the package instead of the type.

 

I'm thinking it has to do with the fact that I am attempting to import a package from the core module into my apps module in the same AEM project.