The Akeyless Java SDK makes it easy for you to integrate your Java applications, libraries, or scripts with the Akeyless Vault platform. The following Java code examples show a typical sequence of how to integrate secrets into your Java applications.


Maven Users

If your project uses Maven, add the following repository to your Maven configuration file
(by default, it is located at ~/.m2/settings.xml):


Then, add the following dependency to your project's pom.xml file:

  <version>Specify the SDK version here</version>


Don't forget to modify the value of the <version> element in the pom.xml file to specify the dependency version you want to include.

Build from Source

Clone the SDK Repository and execute:

mvn clean package

Then, manually install the JAR files under the target folder.


The example below uses the following imported packages:

import io.akeyless.client.ApiClient;
import io.akeyless.client.ApiException;
import io.akeyless.client.Configuration;
import io.akeyless.client.model.Configure;
import io.akeyless.client.model.ConfigureOutput;
import io.akeyless.client.model.ListItems;
import io.akeyless.client.model.ListItemsInPathOutput;

To begin configuring the Java SDK, create and configure an instance of Akeyless Client:

ApiClient client = Configuration.getDefaultApiClient();
V2Api api = new V2Api(client);

The Akeyless Gateway URL should be one of the following:

  • A public instance of the Akeyless Gateway. It is shared between all accounts and does not support Akeyless Zero-Knowledge Encryption.
  • A private Akeyless Gateway deployment. Note that it uses port :8081.
  • A private Akeyless Gateway deployment that uses the legacy API port with the /v2 path prefix.


The Akeyless Java SDK supports multiple authentication methods. The following example uses an API Key for authentication:

Configure body = new Configure();
ConfigureOutput out;
out = api.configure(body);
String token = out.getToken();

Using cloud ID

Add this dependency to your project's POM:

  <version>Specify the CloudId package version here</version>

Import the following to your project:

import io.akeyless.client.ApiException;
import io.akeyless.cloudid.CloudProviderFactory;
import io.akeyless.cloudid.CloudIdProvider;

Authenticate using cloud ID

// Use azure_ad/aws_iam/gcp, according to your cloud provider
CloudIdProvider idProvider = CloudProviderFactory.getCloudIdProvider(accessType);
try {
    String cloudId = idProvider.getCloudId();
    V2Api api = new V2Api(client);
    Auth auth = new Auth();
    auth.accessId("<Your auth method access id>");

    AuthOutput out = api.auth(auth);
    String token = out.getToken();
} catch (ApiException e) {
    System.err.println("Status code: " + e.getCode());
    System.err.println("Reason: " + e.getResponseBody());
    System.err.println("Response headers: " + e.getResponseHeaders());
} catch (Exception e) {
    System.err.println("Reason: " + e.getMessage());

Usage Examples

List Items

ListItems listBody = new ListItems();
listBody.setToken(token); // set the token received during authentication
ListItemsInPathOutput listOut = api.listItems(listBody);

API Reference

For a detailed API reference, see here.