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
- Ensure that the necessary dependencies for
dbutils
are included in your Java project. Reference the Databricks SDK for Java (AWS | Azure | GCP) documentation to include the required libraries. - 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>
- Rebuild your jar file with the updated dependencies and deploy it to your Databricks environment.
- Rerun your jar job.