Expand my Community achievements bar.

SOLVED

AEM project app cannot resolve package dependency in core

Avatar

Level 2

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"%>

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 10

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.

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

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.

Avatar

Level 2

Hi,

 

statusutil is a class where the package is com.site.assets.core.utils.

 

I am attempting to import the statusutil class so that I can use a static method inside the class to retrieve a status. However, on the import of the class I am getting the exception which I am confused about since I am able to link to it and build the project. At runtime it just seems that it cannot find the class to import.

Avatar

Level 10
Did you try the things I mentioned in my answer? Also, why is statsutil in lowercase? Shouldn't it be called StatsUtil if its a class?

Avatar

Level 2

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.