The License.getInstance().getBuilder()
method is your entry point for configuring every aspect of
your software's licensing. This method returns an instance of the Builder class, which provides a fluent and
intuitive API designed to simplify the setup process.
Through this Builder, you can define all the essential settings for your software license, ensuring it behaves
precisely as required. This includes specifying critical details such as the product's unique identifier, the
desired persistence mechanism and location for license data (e.g., a specific file path on disk or a key within
the Windows Registry), parameters for generating a unique device fingerprint to bind licenses to specific
hardware, and the network address of your license server for online validation and activation. By centralizing
these configurations within the Builder, you gain a clear, organized, and robust way to prepare your license
instance before it's used throughout your application.
// All options used.
License.getInstance().getBuilder()
.product("product-hash-code") // the only required argument
.file(System.getProperty("user.home") + "/MyProduct/license.l4j") // license file location to save and load
.registry("MyProduct", "license") // on Windows, save and load license to registry
.feature("edition", mySoftwareEdition) // a feature if needed
.feature("version", "1.1.0") // a feature if needed
.feature("some-feature-name", "enabled") // any custom feature
.server("https://license.company.com") // if using on-premises license server
.build();
.product(String productHashValue)
: Within the LICENSE4J system, each product is uniquely identified by a
hash
value derived from its public key. This distinct hash plays a crucial role in the licensing process: it's used to
efficiently locate and associate the correct product when a license activation request is received by the server.
This mechanism ensures that incoming license keys are accurately matched to their corresponding software products
for validation and activation.
.file(String file)
: method is used to explicitly define the precise location where the license data will be
loaded from and saved to. If it is not specified, the system defaults to a structured path within the current
user's home
directory. This default path is constructed by appending a unique identifier derived from the product's hash code.
Specifically, it uses the last eight characters of the product's hash code to create a distinct subfolder.
94E1B381016BEE2CBC5F644B6F078C28
and the current username is john, the
default license file location on a Windows operating system would be C:\Users\john\.6F078C28\license.l4j
.
System.getProperty("user.home") + File.separator + "." + {last 8 characters of hash code} + File.separator +
"license.l4j"
This automatic fallback ensures that a consistent and isolated location is used for license
persistence, even when
a custom path is not explicitly provided.
.registry(String registryKey, String registryValue)
: method is specifically designed for Windows
environments to designate the location within the system registry for loading and saving license data. If this
method is not explicitly defined, the registry will not be utilized for license persistence on Windows systems; in
such cases, the license data would typically default to file-based storage.
HKEY_CURRENT_USER\SOFTWARE\
. For instance, by calling
registry("MySoftware", "license")
, the license data will be saved and subsequently loaded from the
HKEY_CURRENT_USER\SOFTWARE\MySoftware\
registry key. The actual license information will be stored as a REG_BINARY
value named license within this path. This method provides a robust and centralized way to manage license data
within the Windows operating system's native configuration store.
.feature(String key, Object value)
: method provides a powerful mechanism for embedding custom attributes or
functionalities directly into your license definition. This method allows you to associate any key-value pair with
a license, effectively extending its capabilities beyond standard parameters like expiry dates or user counts.
.customFingerprint(String fingerprint)
: method offers powerful flexibility by allowing you to define a
custom hardware fingerprint for license validation. While LICENSE4J provides its own robust fingerprinting
mechanisms, this method enables you to integrate any unique identifier you choose to bind a license to a specific
device or environment.
customFingerprint
, you gain fine-grained control over how your licenses are locked to particular
installations. This is especially beneficial for scenarios where standard hardware IDs might be insufficient, or
when you need to align licensing with existing internal identification systems. During validation, the license
server will check if the custom fingerprint provided by the client matches the one stored with the activated
license, ensuring that the software is used only on the intended system.
.usbDongle(String vendorId, String productId, String licenseFileNamePath)
: method provides a highly flexible
way to implement USB-based license dongles, allowing virtually any brand or model of USB stick or external disk to
serve as a physical license key. This offers a tangible, portable licensing solution for your software.