Tuesday, December 25, 2018

com.google.appengine.tools.admin.AdminException: Unable to stage app: Cannot get the System Java Compiler. Please use a JDK, not a JRE - Google SDK App Deployment

I was getting the below exception while deploying the application through google cloud SDK command line interface - gcloud app deploy appengine-web.xml

gcloud-app-deploy-no-jdk

Unable to stage:
java.lang.RuntimeException: Cannot get the System Java Compiler. Please use a JDK, not a JRE.
at com.google.appengine.tools.admin.Application.compileJspJavaFiles(Application.java:1297)
at com.google.appengine.tools.admin.Application.compileJsps(Application.java:1273)
at com.google.appengine.tools.admin.Application.populateStagingDirectory(Application.java:983)
at com.google.appengine.tools.admin.Application.createStagingDirectory(Application.java:875)
at com.google.appengine.tools.admin.AppAdminImpl.stageApplication(AppAdminImpl.java:539)
at com.google.appengine.tools.admin.AppAdminImpl.stageApplicationWithDefaultResourceLimits(AppAdminImpl.java:492)
at com.google.appengine.tools.admin.AppCfg$StagingAction.execute(AppCfg.java:2508)
at com.google.appengine.tools.admin.AppCfg.executeAction(AppCfg.java:363)
at com.google.appengine.tools.admin.AppCfg.<init>(AppCfg.java:211)
at com.google.appengine.tools.admin.AppCfg.<init>(AppCfg.java:118)
at com.google.appengine.tools.admin.AppCfg.main(AppCfg.java:114)
com.google.appengine.tools.admin.AdminException: Unable to stage app: Cannot get the System Java Compiler. Please use a JDK, not a JRE.
at com.google.appengine.tools.admin.AppAdminImpl.stageApplication(AppAdminImpl.java:543)
at com.google.appengine.tools.admin.AppAdminImpl.stageApplicationWithDefaultResourceLimits(AppAdminImpl.java:492)
at com.google.appengine.tools.admin.AppCfg$StagingAction.execute(AppCfg.java:2508)
at com.google.appengine.tools.admin.AppCfg.executeAction(AppCfg.java:363)
at com.google.appengine.tools.admin.AppCfg.<init>(AppCfg.java:211)
at com.google.appengine.tools.admin.AppCfg.<init>(AppCfg.java:118)
at com.google.appengine.tools.admin.AppCfg.main(AppCfg.java:114)
Caused by: java.lang.RuntimeException: Cannot get the System Java Compiler. Please use a JDK, not a JRE.
at com.google.appengine.tools.admin.Application.compileJspJavaFiles(Application.java:1297)
at com.google.appengine.tools.admin.Application.compileJsps(Application.java:1273)
at com.google.appengine.tools.admin.Application.populateStagingDirectory(Application.java:983)
at com.google.appengine.tools.admin.Application.createStagingDirectory(Application.java:875)
at com.google.appengine.tools.admin.AppAdminImpl.stageApplication(AppAdminImpl.java:539)
... 6 more

The Java/Javac versions and the JAVA_HOME and PATH variables were configured properly.

gcloud-app-deploy-no-jdk

Also the java runtime was configured properly in appengine-web.xml

gcloud-app-deploy-no-jdk

After little struggle,  the root cause of the issue was with wrong configuration of PATH environment variable.

Other Java executables added to the PATH variable caused the SDK to choose the JRE version for deployment. 

gcloud-app-deploy-no-jdk


The issue got fixed after changing the order of PATH variable - moved up the JAVA bin path over other path configurations

gcloud-app-deploy-no-jdk



Monday, December 24, 2018

How to enable the authors to override or add new meta tags to the pages? - Adobe Experience Manager(AEM)

How to enable the authors to override or add new meta tags to the pages? - Adobe Experience Manager(AEM)


The custom meta tags in AEM are predefined in components with required values - the values can be dynamically taken from properties or external system in case of eCommerce websites,  the authors will not be able to overwrite(the values can be changed but some cases we may required the value should be changed only for meta tags but not in the source) or add new meta tags during the page authoring.

Meta tags in page components:

meta-tags-aem

meta-tags-aem


This post will explain the approach to enable the authoring capability to override the meta tags defined in the page components and also to add new meta tags to the pages.

Enabling the meta tag management(overridden the existing meta tags and add new meta tags ) for author:

Override the Page Proprieties to add additional tab to define meta tags:


Create a node cq:dialog under page component(e.g /apps/weretail/components/structure/page/)

Name  : cq:dialog
Type : nt:unstructured

Property

sling:resourceType cq/gui/components/authoring/dialog

Create a node content under /apps/weretail/components/structure/page/cq:dialog

Name  : content
Type : nt:unstructured

Create a node items under /apps/weretail/components/structure/page/cq:dialog/content

Name  : items
Type : nt:unstructured

Create a node tabs under /apps/weretail/components/structure/page/cq:dialog/content/items

Name  : tabs
Type : nt:unstructured

Create a node items under /apps/weretail/components/structure/page/cq:dialog/content/items/tabs

Name  : items
Type : nt:unstructured

Create a node metatags under /apps/weretail/components/structure/page/cq:dialog/content/items/tabs/items

Name  : metatags
Type : nt:unstructured

Properties

jcr:title Meta Tags
sling:resourceType granite/ui/components/coral/foundation/fixedcolumns

Create a node items under /apps/weretail/components/structure/page/cq:dialog/content/items/tabs/items/metatags

Name  : items
Type : nt:unstructured

Create a node column under /apps/weretail/components/structure/page/cq:dialog/content/items/tabs/items/metatags

Name  : column
Type : nt:unstructured

Properties
sling:resourceType granite/ui/components/coral/foundation/container

Create a node items under /apps/weretail/components/structure/page/cq:dialog/content/items/tabs/items/metatags/column

Name  : items
Type : nt:unstructured

Create a node overridemetatags  under /apps/weretail/components/structure/page/cq:dialog/content/items/tabs/items/metatags/column/items

Name  : overridemetatags
Type : nt:unstructured

Properties
composite true
fieldLabel Override Meta tags
sling:resourceType granite/ui/components/coral/foundation/form/multifield

Create a node newmetatags  under /apps/weretail/components/structure/page/cq:dialog/content/items/tabs/items/metatags/column/items

Name  : newmetatags
Type : nt:unstructured

Properties
composite true
fieldLabel New Meta tags
sling:resourceType granite/ui/components/coral/foundation/form/multifield

Create a node field  under /apps/weretail/components/structure/page/cq:dialog/content/items/tabs/items/metatags/column/items/overridemetatags

Name  : field
Type : nt:unstructured

Properties
name ./overRideMetadata
sling:resourceType granite/ui/components/coral/foundation/container

Create a node items  under /apps/weretail/components/structure/page/cq:dialog/content/items/tabs/items/metatags/column/items/overridemetatags/field

Name  : items
Type : nt:unstructured

Create a node metaname  under /apps/weretail/components/structure/page/cq:dialog/content/items/tabs/items/metatags/column/items/overridemetatags/field/items

Name  : metaname
Type : nt:unstructured

Properties
name ./metaname
fieldLabel Meta tag Name
sling:resourceType granite/ui/components/coral/foundation/form/textfield

Create a node metavalue  under /apps/weretail/components/structure/page/cq:dialog/content/items/tabs/items/metatags/column/items/overridemetatags/field/items

Name  : metavalue
Type : nt:unstructured

Properties
name ./metavalue
fieldLabel Meta tag Value
sling:resourceType granite/ui/components/coral/foundation/form/textfield

Create a node field  under /apps/weretail/components/structure/page/cq:dialog/content/items/tabs/items/metatags/column/items/newmetatags

Name  : field
Type : nt:unstructured

Properties
name ./newMetadata
sling:resourceType granite/ui/components/coral/foundation/container

Create a node items  under /apps/weretail/components/structure/page/cq:dialog/content/items/tabs/items/metatags/column/items/newmetatags/field

Name  : items
Type : nt:unstructured

Create a node metaname  under /apps/weretail/components/structure/page/cq:dialog/content/items/tabs/items/metatags/column/items/newmetatags/field/items

Name  : metaname
Type : nt:unstructured

Properties
name ./metaname
fieldLabel Meta tag Name
sling:resourceType granite/ui/components/coral/foundation/form/textfield

Create a node metavalue  under /apps/weretail/components/structure/page/cq:dialog/content/items/tabs/items/metatags/column/items/newmetatags/field/items

Name  : metavalue
Type : nt:unstructured

Properties
name ./metavalue
fieldLabel Meta tag Value
sling:resourceType granite/ui/components/coral/foundation/form/textfield


Saturday, December 15, 2018

Different approaches to dynamically include custom scripts into websites - Adobe Experience Manager(AEM)

Different approaches to include custom scripts dynamically into websites - Adobe Experience Manager(AEM)


Sometimes we may need to include scripts dynamically into the websites with out changing the code, this post will explain the different approaches to include the scripts dynamically in the websites without performing the code changes.

Tag Manager:


Inject the custom scripts remotely through tag manager systems, this will provide better management of tags without changing the code.

GTM(Google Tag Manager) - Refer https://www.albinsblog.com/2018/12/how-to-include-dynamic-custom-scripts-website-gtm.html for details on injecting the custom script through GTM.

AdobeLaunch-Refer https://www.albinsblog.com/2018/12/how-to-include-dynamic-custom-scripts-adobe-launch-aem.html for details on injecting the custom script through Adobe Launch.

AEM Cloud configuration:


This approach uses the custom AEM Cloud Configuration to include the dynamic scripts - header and footer to the website

Define a Cloud configuration to enable the header and footer scripts and attach the cloud configuration to the required websites to inject the custom dynamic scripts.

Steps-

In CRXDE Lite, create a new node under /apps:

Name: utilities
Type: nt:folder

Create 2 new nodes under /apps/utilities:

Name: components
Type: sling:Folder
and
Name: templates
Type: sling:Folder

Right click on /apps/utilities/components, create a new component genericscriptpage

Label - genericscriptpage
Title - genericscriptpage

group - .hiddenSuperType-cq/cloudserviceconfigs/components/configpage

Add the below additional properties

cq:defaultView - html
allowedParents - utilities/templates/genericscript

Remove the default genericscriptpage.jsp and create content.jsp file under /apps/utilities/components/genericscriptpage with the following content

<%@page session="false" 
  contentType="text/html"
  pageEncoding="utf-8"%><%
%><%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0" %><%

%><cq:defineObjects/>
<div>
    <h3>General Script Settings</h3>   
    <ul>
<li><div class="li-bullet"><strong>Head Script: </strong><br><%= xssAPI.encodeForHTML(properties.get("headScript", "")).replaceAll("\\&\\#xa;","<br>") %></div></li>
<li><div class="li-bullet"><strong>Foot Script: </strong><br><%= xssAPI.encodeForHTML(properties.get("footScript", "")).replaceAll("\\&\\#xa;","<br>") %></div></li>
    </ul>
</div>

dynamic-script-aem


Create a new node under/apps/utilities/components/genericscriptpage/:

Name: dialog
Type: cq:Dialog

Properties:

title - Generic Script Configuration
xtype - dialog

Create a new node under/apps/utilities/components/genericscriptpage/dialog:

Name: items
Type: cq:WidgetCollection

Create a new node under /apps/utilities/components/genericscriptpage/dialog/items:

Name: panel
Type: cq:Panel

Properties:

title - Script Configuration
xtype - panel

Create a new node under /apps/utilities/components/genericscriptpage/dialog/items/panel:

Name: items
Type: cq:WidgetCollection

Create a new node headScript under /apps/utilities/components/genericscriptpage/dialog/items/panel/items
Name: headScript
Type: cq:widget

Properties:

fieldLabel - Head Script
name - ./headScript
xtype - textarea

Create a new node footScript under /apps/utilities/components/genericscriptpage/dialog/items/panel/items

Name: footScript
Type: cq:widget

Properties:

fieldLabel - Foot Script
name - ./footScript
xtype - textarea

Create a new component genericscript under /apps/utilities/components

Label - genericscript
Title - genericscript

Remove the default file genericscript.jsp, create a file headScript.jsp and add the below content 

<%--

--%><%@page session="false" 
import="org.apache.sling.api.resource.Resource,
                org.apache.sling.api.resource.ValueMap,
                org.apache.sling.api.resource.ResourceUtil,
                com.day.cq.wcm.webservicesupport.Configuration,
                com.day.cq.wcm.webservicesupport.ConfigurationManager" %><%
%><%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0" %><%
%><cq:defineObjects/><%

String[] services = pageProperties.getInherited("cq:cloudserviceconfigs", new String[]{});
ConfigurationManager cfgMgr = resource.getResourceResolver().adaptTo(ConfigurationManager.class);
if(cfgMgr != null) {
String scriptCode = null;
Configuration cfg = cfgMgr.getConfiguration("generic-script", services);
if(cfg != null) {
scriptCode = cfg.get("headScript", null);
}

if(scriptCode != null) {

%><%= scriptCode %><%

}
}
%>


Create a file footScript.jsp with following content under /apps/utilities/components/genericscript 

<%--

--%><%@page session="false" 
import="org.apache.sling.api.resource.Resource,
                org.apache.sling.api.resource.ValueMap,
                org.apache.sling.api.resource.ResourceUtil,
                com.day.cq.wcm.webservicesupport.Configuration,
                com.day.cq.wcm.webservicesupport.ConfigurationManager" %><%
%><%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0" %><%
%><cq:defineObjects/><%

String[] services = pageProperties.getInherited("cq:cloudserviceconfigs", new String[]{});
ConfigurationManager cfgMgr = resource.getResourceResolver().adaptTo(ConfigurationManager.class);
if(cfgMgr != null) {
String scriptCode = null;
Configuration cfg = cfgMgr.getConfiguration("generic-script", services);
if(cfg != null) {
scriptCode = cfg.get("footScript", null);
}

if(scriptCode != null) {

%><%= scriptCode %><%

}
}
%>
dynamic-script-aem




How to include dynamic custom script to websites through Adobe Launch - Adobe Experience Manager(AEM)

How to include dynamic custom script to websites through Adobe Launch - Adobe Experience Manager(AEM)

Launch, by Adobe is a next-generation tag management system that unifies the client-side marketing ecosystem by empowering developers to build integrations on a robust, extensible platform that partners, clients, and the broader industry can build on and contribute to.

Adobe Launch is the upgraded version of Adobe’s Dynamic Tag Manager (DTM), Adobe’s Dynamic Tag Manager (DTM) will be replaced by Adobe Launch(It doesn’t mean the platform will be shut down anytime soon).

This post explains the approach to use Adobe Launch to include the dynamic scripts as part of Adobe Experience Manager(AEM) websites.

Login to Adobe Launch and create new property- LAUNCH_CUSTOM_SCRIPT, specify the domain as localhost.local for localhost testing and Save the Property.

Adobe_Launch_aem_integration

Define New Rule:


Adobe_Launch_aem_integration

Configure the Event

Adobe_Launch_aem_integration

Configure the Action

Adobe_Launch_aem_integration

Define the script in Editor

Adobe_Launch_aem_integration

var s = document.createElement("script");
s.innerHTML = "alert('Custom Script from GTM');"; // add the custom script content
  //s.src="test.js";// specify the script file instead of script content
document.head.appendChild(s);

Adding multi line script - example

s.innerHTML = "document.onreadystatechange = function(){ "+
    "if(document.readyState=='loaded' || document.readyState=='complete') "+
        "alert('test');"+
"}";



How to include dynamic custom script to websites through GTM(Google Tag Manager) - Adobe Experience Manager(AEM)

How to include dynamic custom script to websites through GTM(Google Tag Manager) - Adobe Experience Manager(AEM)


Google Tag Manager is a tag management system that allows you to quickly and easily update tracking codes and related code fragments collectively known as "tags" on your website or mobile app. Once a small segment of Tag Manager code has been added to your project, you can easily configure and deploy your tag configurations from a web-based user interface without the need to deploy additional code in most cases. This reduces errors and frees you from having to involve a developer every time you need to make changes.

This post explains the approach to use Google Tag Manager(GTM) to include the dynamic scripts as part of Adobe Experience Manager(AEM) websites.


Create a free google tag manager account if one is not available

tagmanager-GTM


Install the GTM header and body scripts to the AEM website

tagmanager-GTM


tagmanager-GTM


Copy the head script to the header file and body script to body footer(start of body section)

tagmanager-GTM

tagmanager-GTM

tagmanager-GTM