Skip to main content
All CollectionsCI/CD Integration
JNI Error when running the RunHawkScan task in Azure DevOps Pipelines
JNI Error when running the RunHawkScan task in Azure DevOps Pipelines

How to resolve JAVA_HOME environment issues when scanning applications in Azure DevOps

Anthony Stinn avatar
Written by Anthony Stinn
Updated over a year ago

Applies To

RunHawkScan task in Azure Pipelines


Issue

When attempting to scan an application in an Azure Pipelines job, the extension's RunHawkScan task fails with a Error: A JNI error has occurred error.

Specifically:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe C:\Users\VssAdministrator\hawk-2.12.0\hawk.ps1 --api-key=*** scan --repo-dir=D:\a\1\s\stackhawk stackhawk.yml  Error: A JNI error has occurred, please check your installation and try again  Exception in thread "main" java.lang.UnsupportedClassVersionError: com/stackhawk/zap/Bootstrap has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0  at java.lang.ClassLoader.defineClass1(Native Method)  at java.lang.ClassLoader.defineClass(ClassLoader.java:756)  at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)  at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)  at java.net.URLClassLoader.access$100(URLClassLoader.java:74)  at java.net.URLClassLoader$1.run(URLClassLoader.java:369)  at java.net.URLClassLoader$1.run(URLClassLoader.java:363)  at java.security.AccessController.doPrivileged(Native Method)  at java.net.URLClassLoader.findClass(URLClassLoader.java:362)  at java.lang.ClassLoader.loadClass(ClassLoader.java:418)  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)  at java.lang.ClassLoader.loadClass(ClassLoader.java:351)  at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601)  exit code : 0  Finishing: Run StackHawk


Cause

The scanner is unable to ascertain the correct Java environment to use because the JAVA_HOME variable is not populated.

This may occur when running the agent on the windows-2019 image -- for instance, via the default Azure Pipelines agent pool. This image utilizes various environment variables for its pre-installed Java environments, none of which is JAVA_HOME:

Version

Vendor

Environment Variable

8.0.362+9 (default)

Eclipse Temurin

JAVA_HOME_8_X64

11.0.18+10

Eclipse Temurin

JAVA_HOME_11_X64

13.0.2+8.1

Adopt OpenJDK

JAVA_HOME_13_X64

17.0.6+10

Eclipse Temurin

JAVA_HOME_17_X64


Solution

Include a Java installer task prior to the HawkScanInstall and RunHawkScan tasks which populates JAVA_HOME.

For instance:

- task: JavaToolInstaller@0
inputs:
versionSpec: '17'
jdkArchitectureOption: 'x64'
jdkSourceOption: 'PreInstalled'

Did this answer your question?