Documentation Index
Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This topic documents how to get started with the Java SDK, and links to reference information on all of the supported features.LaunchDarkly’s SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and sample applications:
| Resource | Location |
|---|---|
| SDK API documentation | SDK API docs |
| Supported SDK Versions | Java server SDK |
| GitHub repository | java-server-sdk |
| Sample applications | Java , You can also use this SDK with Kotlin |
| Published module | Maven |
The LaunchDarkly Java SDK, version 5.0 and higher, is compatible with Java 8 and higher.Prior to version 5.0, the LaunchDarkly Java SDK also supported Java 7.
Get started
After you complete the Getting Started process, follow these instructions to start using the LaunchDarkly SDK in your Java application.Install the SDK
First, install the LaunchDarkly SDK as a dependency in your application using your application’s dependency manager. Refer to the SDK releases page to identify the latest version. In this example, it uses version 7.0.0:The Java SDK uses an SDK key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.
Initialize the client
After you install and import the SDK, create a single, shared instance ofLDClient. Specify your SDK key here to authorize your application to connect to a particular environment within LaunchDarkly.
Here’s how:
isInitialized().
To learn more about the specific configuration properties that are available in this SDK, read LDConfig.Builder.
If you receive an “unable to find valid certification path” error when you initialize the SDK, you must update the Java truststore. To learn how, read the troubleshooting article in the LaunchDarkly Customer Knowledge Base.
Evaluate a context
You can useclient to check which variation a particular context will receive for a given feature flag. To learn more, read Evaluating flags and Flag evaluation reasons. For more information about how contexts are specified, read Context configuration.
In the v6 example, the context key is the string “example-context-key”. In the v5 example, the user key is the string “example-user-key”:
Using the Java SDK in OSGi
You can install versions 4.6.0 and higher of the SDK as OSGi bundles. The SDK’s default jar, which it gets from Maven or Gradle if you do not specify a “classifier,” does not contain Gson or SLF4j because applications are often built with their own specific versions of those libraries. Using the default jar in OSGi requires Gson and SLF4j to be provided by some other bundle. However, there is also a distribution that includes Gson and SLF4j as part of the SDK bundle. You can use this if you do not need to control the versions of those libraries separately. To do so, add the classifier “all”:Shut down the client
Shut down the client when your application terminates. To learn more, read Shutting down.Supported features
This SDK supports the following features:- Anonymous contexts and users
- Big segments
- Configuration, including
- Context configuration
- Data saving mode
- Evaluating flags
- Flag evaluation reasons
- Flushing events
- Getting all flags
- Hooks
- Identifying and changing contexts
- Logging configuration
- Migrations
- Monitoring SDK status
- Offline mode
- OpenTelemetry
- Private attributes
- Reading flags from a file
- Relay Proxy configuration
- Secure mode
- Sending custom events
- Shutting down
- Storing data
- Subscribing to flag changes
- Test data sources
- Web proxy configuration