Set up Java SDK

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 // Set your LaunchDarkly SDK key.
9 // This is inlined as example only for onboarding.
10 // Never hardcode your SDK key in production.
11 final LDClient client = new LDClient("YOUR_SDK_KEY", config);
12
13 if (client.isInitialized()) {
14 // For onboarding purposes only we flush events as soon as
15 // possible so we quickly detect your connection.
16 // You don't have to do this in practice because events are automatically flushed.
17 client.flush();
18 System.out.println("SDK successfully initialized!");
19 }
20 }
21}

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.