"ERROR: Failed to initialize a Java virtual machine in TKJNL" occurs with SAS® Cloud Analytic Services (CAS) actions that use Java


The following error can appear in client or server logs when a CAS action uses Java:

ERROR: Failed to initialize a Java virtual machine in TKJNL

Common actions that use Java are the following:

To resolve this problem, each CAS machine needs a Java Runtime Environment (JRE) and environment variables that enable CAS to find the JRE.

In most cases, you can address this problem by performing the following steps. There are various possibilities for the JRE path, but the example below, which uses the /usr/lib/jvm/jre-1.8.0 symlink path, is highly recommended. Do not use a Java path that contains a specific version (for example, /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre), because that path will not be valid when Java package updates are applied and the path changes.

Steps for Resolving the Problem

  1. On all CAS machines (controllers and all workers), verify that the following directory exists:

   /usr/lib/jvm/jre-1.8.0

If it does not exist, install a 1.8 JRE package from your Linux repositories and check again. The package java-1.8.0-openjdk-headless provides this functionality in most Red Hat Enterprise Linux (RHEL) 7 or 8 based distributions.
 
2. On all CAS machines (controllers and all workers), edit the /opt/sas/viya/config/etc/cas/default/cas_usermods.settings file and add the following lines:

   export JAVA_HOME=/usr/lib/jvm/jre-1.8.0
   export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JAVA_HOME/lib/amd64/server


Note: If it is a multi-tenant environment, modify the /opt/sas/tenant-name/config/etc/cas/default/cas_usermods.settings file to set these variables for each tenant CAS server.

You must perform these steps on all CAS machines in a multi-machine CAS environment. To cover all Java usage scenarios, it is not sufficient to install a JRE and set the variables on the controller only or on the worker nodes only.  

You do not need to restart any services for these changes to take effect. The cas_usermods.settings file is sourced by each new CAS session, so starting a new CAS session is sufficient to test the variables. Starting a new CAS session means running a new CAS statement in a programming session, or logging out and back into a visual interface, such as SAS® Environment Manager.

You can use SAS Environment Manager to check whether the variables are in effect. Navigate to Servers and select cas-shared-default (or tenant-CAS-server-name) ► Configuration ► Nodes ► Choose a node ► Runtime Environment. In the list of environment variables, you should find JAVA_HOME and LD_LIBRARY_PATH.