Java (Server) — SDK detail
- Official docs: Java SDK reference
- API reference: Java server SDK API
- Published artifact: Maven Central
- Recipe (detect / install): SDK Recipes (Java Server)
Pin version to a current release from the SDK releases page. The blocks below mirror Install the SDK (Maven XML and Gradle); use the one that matches your build.
Maven (pom.xml):
<dependency>
<groupId>com.launchdarkly</groupId>
<artifactId>launchdarkly-java-server-sdk</artifactId>
<version>7.0.0</version>
</dependency>Gradle (Groovy) — long form as in the docs:
implementation group: 'com.launchdarkly', name: 'launchdarkly-java-server-sdk', version: '7.0.0'Gradle (Groovy) — common shortcut (still set a concrete or ranged version you intend to support):
implementation 'com.launchdarkly:launchdarkly-java-server-sdk:7.+'Gradle (Kotlin DSL) (build.gradle.kts):
implementation("com.launchdarkly:launchdarkly-java-server-sdk:7.+")OSGi “all” classifier (bundled Gson/SLF4J): see Using the Java SDK in OSGi.
Import (same topic):
import com.launchdarkly.sdk.*;
import com.launchdarkly.sdk.server.*;Initialize: new LDClient(sdkKey) connects with a default ~5s wait; use isInitialized() to see if startup succeeded. For custom timeouts and options, use LDConfig.Builder. LDClient must be a singleton per environment.
Includes: Minimal main sample. SDK key: LAUNCHDARKLY_SDK_KEY (Apply: environment configuration).
import com.launchdarkly.sdk.*;
import com.launchdarkly.sdk.server.*;
public class Main {
public static void main(String[] args) {
String sdkKey = System.getenv("LAUNCHDARKLY_SDK_KEY");
if (sdkKey == null || sdkKey.trim().isEmpty()) {
System.err.println(
"LAUNCHDARKLY_SDK_KEY is not set. Use Project settings > Environments > SDK key.");
System.exit(1);
}
try (LDClient client = new LDClient(sdkKey)) {
if (client.isInitialized()) {
// For onboarding only — events are normally flushed in the background.
client.flush();
System.out.println("LaunchDarkly client initialized.");
} else {
System.err.println(
"LaunchDarkly client did not initialize within the default wait; defaults apply until connected.");
System.exit(1);
}
}
}
}