This page walks through the process of creating a Java application using the Ontology SDK (OSDK).
Before you can create a new Java application with the Ontology SDK (OSDK), you must first create a new Developer Console application page. This will set up your application's permissions and select what objects you want your Java application to use.
Next, export your personal access token in your local environment. This is a token associated with your Palantir user or application that allows you to access Foundry resources through third-party applications and APIs. Below is an example using a sample personal access token, but you can generate a longer-lived one in the Developer Console.
Do not check this token into source control, as this can create a security vulnerability. For instance, you should not include your personal access token in a Git repository.
Copied!1
export FOUNDRY_TOKEN=<YOUR-TOKEN-FROM-GETTING-STARTED-PAGE>
The Java OSDK requires a Java version between 17 and 21. To check what version of Java you are using, run the command below and upgrade Java if necessary.
Copied!1
java --version
Add the following repository and dependency to your build.gradle
file (or equivalent, if you are using a different build tool) in order to install the latest version of the SDK. Replace any < >
with your application-specific value as found on your application Overview page in the Developer Console.
repositories {
maven {
credentials {
username ''
password System.getenv('FOUNDRY_TOKEN')
}
url 'https://<APPLICATION-URL>'
}
maven {
credentials {
username ''
password System.getenv('FOUNDRY_TOKEN')
}
url 'https://<GENERATOR-URL>'
}
}
dependencies {
implementation '<YOUR-PACKAGE-NAME>'
}
In your application, initialize the Foundry client and start developing. If you need to create a service user to host a backend application, a typical use case for integrating the Java SDK into an existing Java service, refer to the guide on obtaining the required OAuth information.
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14
import <PACKAGE-NAME>.FoundryClient; import <PACKAGE-NAME>.objects.Aircraft; import com.palantir.osdk.api.Auth; import com.palantir.osdk.api.UserTokenAuth; import com.palantir.osdk.internal.api.FoundryConnectionConfig; Auth auth = UserTokenAuth.builder().token(System.getenv("FOUNDRY_TOKEN")).build(); FoundryClient client = FoundryClient.builder() .auth(auth) .connectionConfig(FoundryConnectionConfig.builder() .foundryUri("<YOUR-FOUNDRY-URL>") .build()) .build(); System.out.println(client.ontology().objects().<ANY-OBJECT>.fetch(1));
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
import <PACKAGE-NAME>.FoundryClient; import <PACKAGE-NAME>.objects.Aircraft; import com.palantir.osdk.api.Auth; import com.palantir.osdk.api.UserTokenAuth; import com.palantir.osdk.internal.api.FoundryConnectionConfig; Auth auth = ConfidentialClientAuth.builder() .clientId("<YOUR-CLIENT-ID>") .clientSecret("<YOUR-SECURELY-STORED-CLIENT-SECRET>") .build(); FoundryClient client = FoundryClient.builder() .auth(auth) .connectionConfig(FoundryConnectionConfig.builder() .foundryUri("<YOUR-FOUNDRY-URL>") .build()) .build(); System.out.println(client.ontology().objects().<ANY-OBJECT>.fetch(1));