Fix Java warnings

At past time I’m faced with some unexpected behavior on windows environments. The issue occurs when I’m tried to execute java code which communicate with my windows machine: find-bugs maven plugin or IntelliJ IDEA

Symptom:

[java] WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(…) returned error code 5.

How to fix: create HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Prefs and
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\JavaSoft\Prefs keys

Continue reading “Fix Java warnings”

Find out AEM information

List of AEM URLs where we could find some useful information:

  1. Installed AEM version: http://localhost:4502/system/console/status-productinfo
  2. AEM Run Mode:
    1. Open http://localhost:4502/system/console/bundles
    2. Navigate to Status -> Sling Settings menu

AEM start script for developers

In many cases, it’s much simpler to use an external script rather that every time navigate into the crx-quickstart folder and manually clean outdated log files and then manually run start script from bin folder.

Below is my start.bat script file content to automate this actions for Windows:

del /s /q ".\crx-quickstart\logs\*.*"

set CQ_PORT=4502
set CQ_RUNMODE=author,localdev
set CQ_JVM_OPTS=-Xmx2048m -XX:+UseG1GC -XX:-UseGCOverheadLimit -Duser.language=en -Duser.region=US -Duser.timezone=UTC -Djava.awt.headless=true -Dfile.encoding=UTF-8 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8001

cd ./crx-quickstart/bin
call ./start.bat

MacOS:

#!/bin/sh

echo "Clean AEM logs"
find crx-quickstart/logs/ -type f -delete

echo "Set AEM parameters"
export CQ_PORT="4502"
export CQ_DEBUG_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8001"
export CQ_LOCALE_OPTS="-Duser.language=en -Duser.region=US -Duser.timezone=UTC -Dfile.encoding=UTF-8"
export CQ_RUNMODE="author,nosamplecontent"
export CQ_JVM_OPTS="-Djava.awt.headless=true -Xmx2048m -XX:+UseG1GC -XX:-UseGCOverheadLimit $CQ_LOCALE_OPTS $CQ_DEBUG_OPTS"

echo "Start AEM instance"
crx-quickstart/bin/start "$@"

Place this script at the same level as license.properties and proceed to enjoy of AEM developing process.

How to install Windows JDK without installation

Sometimes we want to keep our system as much clean as possible and do not want to install JDK from exe installer for . Below is a brief instruction on how to do it:

  1. Download JDK from Oracle site – link
  2. Install 7-zip if not already installed
  3. create unpack.bat file at the same folder where JDK from step 1 was downloaded with below content depends on JDK version:
    1. bat file for JDK 8:
      @echo off
      set PATH=%PATH%;C:\Program Files\7-Zip\
      
      rmdir /s /q "%~dp0\jdk-out"
      rmdir /s /q "%~dp0\unpacked-jdk"
      7z x %1 -o"%~dp0\jdk-out"
      cd /d "jdk-out\.rsrc\1033\JAVA_CAB10"
      extrac32 111
      7z x tools.zip -ojdk
      cd /d "jdk"
      for /r %%x in (*.pack) do .\bin\unpack200 -r "%%x" "%%~dx%%~px%%~nx.jar"
      mkdir "%~dp0\unpacked-jdk"
      xcopy /s "%~dp0\jdk-out\.rsrc\1033\JAVA_CAB10\jdk" "%~dp0\unpacked-jdk"
      cd /d "%~dp0"
      cd /d "jdk-out\.rsrc\1033\JAVA_CAB9"
      extrac32 110
      xcopy /s "%~dp0\jdk-out\.rsrc\1033\JAVA_CAB9\src.zip" "%~dp0\unpacked-jdk"
      cd /d "%~dp0"
      rmdir /s /q "%~dp0\jdk-out"
    2. bat file for JDK 9:
      @echo off
      set PATH=%PATH%;C:\Program Files\7-Zip\
      
      rmdir /s /q "%~dp0\jdk-out"
      rmdir /s /q "%~dp0\unpacked-jdk"
      7z x %1 -o"%~dp0\jdk-out"
      cd /d "jdk-out"
      7z x tools.zip -ojdk
      cd /d "jdk"
      for /r %%x in (*.pack) do .\bin\unpack200 -r "%%x" "%%~dx%%~px%%~nx.jar"
      mkdir "%~dp0\unpacked-jdk"
      xcopy /s "%~dp0\jdk-out\jdk" "%~dp0\unpacked-jdk"
      cd /d "%~dp0"
      rmdir /s /q "%~dp0\jdk-out"
  4. start above script from command line with single parameter (name of downloaded JDK exe installer file). For example:
    unpack jdk-8u152-windows-x64.exe

    or

    unpack jdk-9.0.1_windows-x64_bin.exe

Continue reading “How to install Windows JDK without installation”

Sling, Git, Windows and Filename too long

There is a common error on Windows systems when you are working with GIT – Filename too long:

error: unable to create file contrib/extensions/distribution/sample/src/main/resources/SLING-CONTENT/libs/sling/distribution/install.publish/impersonate-reverse/org.apache.sling.distribution.packaging.impl.exporter.AgentDistributionPackageExporterFactory-impersonate-reverse.json: Filename too long

What does it means?

It means that by default GIT on Windows has a 260 characters limit due to system limitations (not all Windows apps are properly working with long file names). This can be critical if you will try for example will try to clone Sling application.

Solution

To remove this limitation we should open Windows Power Shell or CMD as administrator and execute command below:

git config --system core.longpaths true

This command will enable long path support and now we could maintain path up to 32,767 characters. For more information you can read this article.

JCR-SQL2 Query with Examples

Introduction

OOTB Apache OAK allow to create queries on SQL(deprecated), XPath(deprecated), JCR-JQOM and JCR-SQL2. It’s obvious that there is not a good point to explain deprecated SQL and XPath. This is a little How-To article which try to cower JCR-SQL2 queries for Apache Jackrabbit/OAK. Apache OAK has a more strict JCR-SQL2 syntax therefore some queries which are working correct on Apache Jackrabbit wouldn’t be executed on Apache OAK so we should always hold this in mind. Anyway let’s deal with JCR-SQL2 queries.
Continue reading “JCR-SQL2 Query with Examples”

How to make JSP scriplets on Java 7, Java 8 and above on Apache Sling and Adobe AEM

Sling implementation allow to render JSP with scriplets (of cause we using scriplets instead of Groovy console for hot-fixes). By default JSP compiler allow to write code compatible with Java 6 therefore if on server we has JVM version greater than 6 and desire to write code for recent JVM with additional benefits like Diamond operators from Java 7 or Lambdas and Streams from Java 8 we should configure JSP Scripts Handler to process required Java version otherwise we will see the compilation error: Continue reading “How to make JSP scriplets on Java 7, Java 8 and above on Apache Sling and Adobe AEM”