Getting NullPointerException when using dbutils.secrets.get in jar jobs

Include the necessary dependencies for dbutils.

Written by girish.sharma

Last published at: December 20th, 2024

Problem

When using the dbutils.secrets.get(scopeName, secretKey) method in a jar job you encounter a NullPointerException.

This issue arises even though the same code works when executed in a notebook. 

 

Cause

The dbutils library is designed for use within notebooks and requires additional configuration to be accessible in jar jobs. 

 

Solution

  1. Ensure that the necessary dependencies for dbutils are included in your Java project. Reference the Databricks SDK for Java (AWSAzureGCP) documentation to include the required libraries.
  2. Add the following dependency to your project's build file (such as pom.xml for Maven). 

 

<dependency>
  <groupId>com.databricks</groupId>
  <artifactId>dbutils-api</artifactId>
  <version>1.0.0</version>
</dependency>

 

  1. Rebuild your jar file with the updated dependencies and deploy it to your Databricks environment.
  2. Rerun your jar job.