Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Cannot run bundle compiled by Java 7/8?

Avatar

Level 2

I hava aem 6.0 SP1 installed. as said in release note. it supports java JRE 8.

Now I have made a bunlde for one service by maven and intellij. when I use java 8 syntax to make the service and set maven-compiler-plugin to both source and target to 1.8.

The bundle can be deployed in console without problem. but the service in it cannot be called by jsp page. when I tried to call by sling.getService. it returned null. and in the error message:

org.apache.sling.api.scripting.ScriptEvaluationException: \n\tat org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:388)\n\tat org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:171)\n\tat org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:463)\n\tat org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:511)\n\tat org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:45)\n\tat org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:64)\n\tat com.day.cq.wcm.core.impl.WCMDeveloperModeFilter.doFilterWithErrorHandling(

I also tried to compile the service bundle in java 7. it still doesn't work. the latest working complier version is 1.6.

So question is: Is the service bundle can only be complied by 1.6? is there any workaround that I can use java 8 syntax to make service bundle?

1 Accepted Solution

Avatar

Correct answer by
Level 9

Usually if there is any error, script should mention cq.Page.Page_jsp, it has iwb added, seeing this first time.

It seems that you have overlaid Page.jsp, if you remove this Page.jsp from /apps/foundation..., does your site work.

Have you tried opening out of box geometrixx sites?

I suggest to perform these steps

1. Install AEM 6.0 on separate port 

2. Check out of box sites whether they work

3. Install and test your application

4. Apply SP1 and test your application

Identify point of failure

View solution in original post

10 Replies

Avatar

Level 9

How are you calling sling.getService method? Is that service available and active?

Have you tried any other sling service?

Avatar

Level 2

I clal the sling.getService in one jsp page. The OSGi bundle jar I uploaded from console page. it's actived and it can see service class name in it. without problem.

i defined maven complier plugin in bundle's pom.xml file as following lines:

  <plugin><artifactId>maven-compiler-plugin</artifactId><version>3.2</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin>

When I use 1.8 to build jar. and upload it by console page. the jsp file shows errors. After I changed source and target to 1.6 or just remove complier plugin. the jar I build works fine with same jsp file.

the issue happens on default helloService generated from aem maven archtype as well.

Avatar

Level 9

Please make sure that intellij supports java 8 and compiler is using jdk 1.8 complieance, please add java 8 support for inttellij if missing.

Your installed JRE should be pointing to 1.8 version and when you run your build make sure JRE is set to workspace default (which will be 1.8 in your case)

Avatar

Level 2

I'm using intellij 14. and the project structure has been set to 1.8. jdk is 1.8.

everything is fine if i remove source/target config from mavn plugins node. if i set to 1.7 or 1.8. build successful. but cannot use the osgi service at all.

here is more information:

java.lang.NullPointerException at org.apache.jsp.apps.foundation.components.primary.cq.Page.Page_iwb_jsp._jspService(Page_iwb_jsp.java:153) at org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:502) at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:449) at org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:281) at org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:102) at org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:524) at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:361) at org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:171) at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:463) at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:533) at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:45) at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:64) at com.day.cq.personalization.impl.TargetComponentFilter.doFilter(TargetComponentFilter.java:96) at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilter(WCMDebugFilter.java:146) at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) at com.day.cq.wcm.core.impl.WCMComponentFilter.filterRootInclude(WCMComponentFilter.java:357)

Avatar

Correct answer by
Level 9

Usually if there is any error, script should mention cq.Page.Page_jsp, it has iwb added, seeing this first time.

It seems that you have overlaid Page.jsp, if you remove this Page.jsp from /apps/foundation..., does your site work.

Have you tried opening out of box geometrixx sites?

I suggest to perform these steps

1. Install AEM 6.0 on separate port 

2. Check out of box sites whether they work

3. Install and test your application

4. Apply SP1 and test your application

Identify point of failure

Avatar

Community Advisor

What is CQ trying to do inside the:

Page_iwb_jsp.java file at line 153 ?

Avatar

Level 2

the page_iwb is the jsp page override default page.jsp. I putted it to foundation/components/primary/cq/page.

I use it to handle url ends with .iwb. here is code of the page:

<%@include file="/libs/foundation/global.jsp"%><%@page session="false"
    contentType="application/json"
            import="com.day.cq.commons.Doctype,
                    com.day.cq.wcm.api.WCMMode,
                    com.day.cq.wcm.foundation.ELEvaluator,
                    com.*.*" %><%
%><%
            com.*.IwbPackageService packageService = sling.getService(com.*.IwbPackageService.class);
            String jsonData=packageService.getPackageData(currentPage.getPath());
                %><%=jsonData %>

it calls IwbPackageService which the OSGi service is. and getPackageData as json format.

the code works fine if i build iwbpackageservice under java 1.6. otherwise. the sling.getService will return null.

it doesn't matter. if I just don't use iwb page. i just call the service at regular page. same issue happens.

Avatar

Employee

Is your AEM also running Java8?

Can you verify that via /system/console?

Avatar

Level 2

here is my system info:

                            
Java Information:
Java RuntimeJava(TM) SE Runtime Environment(build 1.8.0_31-b13)
Java Virtual MachineJava HotSpot(TM) 64-Bit Server VM(build 25.31-b07, mixed mode)
Number of Processors4
Total Memory1270272
Used Memory485214
Free Memory785058