SDKs
...
Getting Started
Java

Java SDK Configuration and Usage

11min
within this guide, we will meticulously navigate the sequential procedure of enabling your licensespring license by employing the licensespring java sdk as you progress through this tutorial, you will acquire the skills to initiate, deactivate, and verify licenses directly from your java program functions and methods used throughout this tutorial throw exceptions to understand any potential problems for more information about these, see java exception handling docid\ fkkfuejtoulifqahzxpig configuration to initialize the sdk you will need to fill in your application name and version, licensespring api key, shared key and product code both the api key and shared key can be found on your licensespring account under settings >keys api and shared key location your product code is located in your product list under "configure products" product code location please, keep in mind that the product code field is case sensitive when you have the necessary values, create the configuration licensespringconfiguration configuration = licensespringconfiguration builder() apikey("xxxxxxxx xxxx xxxx xxxx xxxxxxxxxxxx") productcode("javatutorial") sharedkey("xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxx") appname("name") appversion("version") build(); now you can initialize licensemanager using this configuration object licensemanager licensemanager = licensemanager getinstance(); try { licensemanager initialize(configuration); } catch (licensespringexception e) { system out println(e getcause() getmessage()); } license activation the license keys are located in "licenses" section on the vendor platform license key location to implement user based licensing please refer to user based licensing docid\ xepx04m3oh f6s8ylf6mz to activate a license, create a activationlicense using the given key and call activation method activationlicense key = activationlicense fromkey("xxxx xxxx xxxx xxxx"); license currentlicense = licensemanager activatelicense(key); currentlicense = licensemanager checklicense(currentlicense); note we immediately check our license after activating because activatelicense only activates the license on the licensespring servers the license check either creates/updates the local license file, depending on if it existed prior license deactivation deactivating a license unbinds the device from the license, and decrements the number of total activations depending on the license transfer policy, this usually means that the license is freed up to be activated onto a new device deactivating is done using the following method if (licensemanager deactivatelicense(licenseidentity fromkey("xxxx xxxx xxxx xxxx"))) { system out println("license deactivated successfully "); } local license the local license is a copy of the license information that is saved on the end user's local computer users who have not activated the license on their end before will not have a local license by default, the local license is stored %userprofile%\appdata\local\licensespring\”product code”\license key see local license file docid\ fkfzhha n838tznrzu0sz for more information if a device already has a license, and you try to activate another license on that device, for the same product, that newly activated license will override the existing license, deleting it from the device this will be on the developer to make sure that they check if a license exists on the device before a new activation license license = licensemanager getcurrent(); if (license == null ) { //activate a new license } license check it is recommended to perform a local license check at application start to confirm that the local license file belongs to the current device and has not been transferred license localcheck(); note it is also useful to check whether the local license file has been tampered with and whether the local license is still valid online license check refreshes the local license with the data from licensespring backend license = licensemanager checklicense(license); full code sample below you can find a code sample that initializes the sdk, retrieves a local license or activates a new one, and performs the necessary checks licensespringconfiguration configuration = licensespringconfiguration builder() apikey("xxxxxxxx xxxx xxxx xxxx xxxxxxxxxxxx") productcode("javatutorial") sharedkey("xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxx") appname("name") appversion("version") build(); licensemanager licensemanager = licensemanager getinstance(); try { licensemanager initialize(configuration); license currentlicense = licensemanager getcurrent(); if (currentlicense == null) { activationlicense key = activationlicense fromkey("xxxx xxxx xxxx xxxx"); currentlicense = licensemanager activatelicense(key); } currentlicense = licensemanager checklicense(currentlicense); currentlicense localcheck(); //additional check, not needed of you're doing online check, but good for offline mode } catch (licensespringexception e) { system out println(e getcause() getmessage()); }