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.

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
API and Shared Key Location


Your product code is located in your product list under "Configure Products":

Product Code Location
Product Code Location


Please, keep in mind that the product code field is case-sensitive.

When you have the necessary values, create the configuration.

Java


Now you can initialize LicenseManager using this configuration object:

Java


License Activation

The license keys are located in "Licenses" section on the vendor platform:

License Key Location
License Key Location


To implement user-based licensing please refer to: User-Based Licensing.

To activate a license, create a ActivationLicense using the given key and call activation method.

Java


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:

Java


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 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:

Java


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.

Java


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:

Java


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.

Java