Skip to content

ivorp/java-client

 
 

Repository files navigation

LaunchDarkly SDK for Java

Circle CI

Quick setup

  1. Add the Java SDK to your project

     <dependency>
       <groupId>com.launchdarkly</groupId>
       <artifactId>launchdarkly-client</artifactId>
       <version>1.0.1</version>
     </dependency>
    
  2. Import the LaunchDarkly package:

     import com.launchdarkly.client.*;
    
  3. Create a new LDClient with your API key:

     LDClient ldClient = new LDClient("YOUR_API_KEY");
    

Your first feature flag

  1. Create a new feature flag on your dashboard

  2. In your application code, use the feature's key to check wthether the flag is on for each user:

     LDUser user = new LDUser(username);
     boolean showFeature = ldClient.toggle("your.feature.key", user, false);
     if (showFeature) {
       // application code to show the feature 
     }
     else {
       // the code to run if the feature is off
     }
    

Troubleshooting

  1. Json parsing exception: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was....ExceptionType: com.google.gson.JsonSyntaxException Make sure your build tool is bringing in the proper version of Gson. The LaunchDarkly SDK may have problems with versions earlier than 2.2.4. To enforce the proper version add this dependency:

    <dependency>
    	<groupId>com.google.code.gson</groupId>
    	<artifactId>gson</artifactId>
    	<version>2.2.4</version>
    </dependency>
    
  2. SSL exceptions when calling toggle(): Make sure your build tool is bringing in the proper version of the Apache http client. The LaunchDarkly SDK may have problems with versions earlier than 3.3.6. To enforce the proper version add this dependency:

    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpclient</artifactId>
      <version>4.3.6</version>
    </dependency>
    

Learn more

Check out our documentation for in-depth instructions on configuring and using LaunchDarkly. You can also head straight to the complete reference guide for this SDK or our Javadocs.

Contributing

We encourage pull-requests and other contributions from the community. We've also published an SDK contributor's guide that provides a detailed explanation of how our SDKs work.

About LaunchDarkly

About

LaunchDarkly SDK for Java

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%