Set up Java SDK

LaunchDarkly onboarding is not available in federal environments
To learn more, read LaunchDarkly in federal environments.

Install the package

1<dependency>
2 <groupId>com.launchdarkly</groupId>
3 <artifactId>launchdarkly-java-server-sdk</artifactId>
4 <version>7.0.0</version>
5</dependency>

Initialize the SDK

Java SDK initialization
1import com.launchdarkly.sdk.*;
2import com.launchdarkly.sdk.server.*;
3
4public class Main {
5 public static void main(String[] args) {
6 LDConfig config = new LDConfig.Builder().build();
7
8 // This is your LaunchDarkly SDK key.
9 // Never hardcode your SDK key in production.
10 final LDClient client = new LDClient("YOUR_SDK_KEY", config);
11
12 if (client.isInitialized()) {
13 // For onboarding purposes only we flush events as soon as
14 // possible so we quickly detect your connection.
15 // You don't have to do this in practice because events are automatically flushed.
16 client.flush();
17 System.out.println("SDK successfully initialized!");
18 }
19 }
20}

You can find your server-side SDK key, client-side ID, and mobile key in the “Resources” section of the help menu. Click the help icon at the bottom left corner of the LaunchDarkly UI, then choose SDK keys:

The SDK keys option in the help menu.

The SDK keys option in the help menu.

To learn more, read Initialize the client in the Java SDK reference guide.