Setting the JOpt License — setLicenseJSON(...) in Java
This document explains how to configure the optimization license for JOpt TourOptimizer (Java) and how the repository example SetLicenseExample applies it.
Clickable links
When you need a license
Without a license, JOpt runs in free mode with up to 10 optimization elements (nodes and resources are counted as elements). The other examples in this repository set the public evaluation license through ExampleLicenseHelper, which allows up to 20 elements. The extended free license allows up to 30 nodes and 7 resources (37 elements); it is available only with a free sign-up on the DNA Evolutions website. Larger problems need a full license.
If you need more elements during your evaluation phase, feel free to contact us.
Implication:
- Small “hello world” scenarios may run without an explicit license (depending on element count).
- Realistic scenarios typically exceed the limit and must set a valid license.
What the license is
A JOpt license is provided as a JSON definition. You can set it either:
- As a JSON string, or
- As a file containing the JSON.
The documentation also warns:
- Changing any JSON key (deleting/modifying/adding) deactivates the license.
- The only allowed modification is formatting (e.g., prettifying).
Two supported application methods
Option A — Set license via JSON string
Use this when:
- you store license content in a secret manager,
- you inject it via environment variables,
- you load it from a database or configuration service.
Minimal pattern:
String myJsonLicense = "{ ... your license JSON ... }";
myOpti.setLicenseJSON(myJsonLicense);
In the example repository, this is demonstrated by a helper method that sets setLicenseJSON(String).
Option B — Set license via file
Use this when:
- you deploy the license as a file on the host,
- you mount it as a secret/volume (Docker/Kubernetes),
- you want to keep credentials out of your code and out of environment variables.
Minimal pattern:
File licFile = new File("/path/to/license.dli");
myOpti.setLicenseJSON(licFile);
In the example repository, the license file path is:
src/main/resources/YOUR_LICENSE.dli
The example checks whether the file exists and only sets the license if it does. If the file is missing, it simply does not set a license (which is a safe behavior for demo/free-mode scenarios).
How the example (SetLicenseExample) is structured
The example follows a clean “bootstrap first” approach:
- Set license (file-based by default)
- Add properties
- Add nodes
- Add resources
- Run optimization
Key takeaway: set your license as early as possible, before starting the run.
Recommended practices for production environments
1) Never commit licenses to source control
Treat the license JSON as a secret:
- do not store it in your repository,
- do not embed it in compiled artifacts.
Prefer:
- secret managers (Vault, AWS Secrets Manager, Azure Key Vault),
- Kubernetes Secrets mounted as files,
- secure CI variables injected at runtime.
2) Prefer file-based configuration for containers
In containerized deployments, the simplest secure pattern is:
- mount the license file into the container, and
- point the application to that path.
This also makes rotation easier (swap the mounted secret).
3) Validate the presence of a license before “real runs”
For long-running services, fail fast with a clear message if the license is missing, instead of silently running in a restricted mode.
A common pattern:
- “demo mode” allowed only in local/dev profiles,
- “production” requires the license to be present.
4) Keep the license JSON untouched
Because modifying keys invalidates the license, any automation around loading/storing should:
- treat the JSON as an opaque value,
- avoid “re-serializing” it through another JSON library that might reorder/alter keys.
Formatting-only changes are acceptable; semantic changes are not.
Notes for the Docker / REST variant
The license documentation states that when using the Docker version of JOpt TourOptimizer, you must send the JSON license definition along with your request.
If you use the REST service:
- keep the license in your request-building pipeline,
- and handle errors centrally so a missing/invalid license is diagnosed immediately.
Quick checklist
- Using more than 10 elements without a license, more than 20 with the public evaluation license, or more than 30 nodes or 7 resources with the extended free license? Provide a license with a higher limit.
- Decide: string-based or file-based injection.
- Store license securely (never in git).
- Do not modify JSON keys.
- Set license before starting the optimization run.