Skip to main content

Java SDK

We now present a high-level Java API as a type-safe and gentle wrapper for the OpenMetadata backend. The open-source OpenMetadata SDK for Java simplifies provisioning, managing, and using OpenMetadata resources from the Java application code.
The OpenMetadata SDK for Java libraries build on top of the underlying OpenMetadata REST API, allows you to use those APIs through familiar Java paradigms. However, you can always use the REST API directly from Java code, if you prefer to do so.
You can find the source code for the OpenMetadata libraries in the GitHub repository. As an open-source project, contributions are always welcome! You can add the below Maven Dependency for the OpenMetadata Java SDK.

Connect to the OpenMetadata Server

To connect to your OpenMetadata server, you need:
  • Server URL: The URL where your OpenMetadata instance is running, ending in /api. For example, http://localhost:8585/api.
  • Access token: A JSON Web Token (JWT) for a user or bot. See Authentication to learn how to get one.
Tune the connection with these options. Timeouts are in milliseconds, and header adds a custom header to every request:

Authenticate with a JWT Token

The Java SDK authenticates with a JWT access token that you pass to accessToken(...). This is the same for every sign-in method on your OpenMetadata server, including Google, Okta, Auth0, Azure, and custom OpenID Connect (OIDC). Generate a bot token or a personal access token in OpenMetadata and use it here. If your server doesn’t require authentication, leave out accessToken(...).

Use the Fluent API

The fluent classes, such as Tables, Users, and Teams, work with a default client. Register your client once with OM.init, and the fluent classes use it:

Use the Service Clients

Every entity type has a service on the client, such as client.tables(), client.users(), and client.dashboards(). These services offer methods such as create, get, getByName, list, update, delete, and restore. Below are some examples:
The following examples show how to call an API:
  • Create a table
  • Get a table by fully qualified name
  • Search
The search call returns the raw JSON response from the server as a string.

Handle Errors

When the server returns an error, the SDK throws an OpenMetadataException. Use getStatusCode() to see which error it was:

More examples

Review the OpenMetadata Java SDK examples for more usage patterns.