We purchased Aspose Total for Java, and my code is shown below
BaseDocGenerator.java
//set regular license
License license = new License();
InputStream in =
this.getClass()
.getClassLoader()
.getResourceAsStream(LICENSE_PATH + “Aspose.Total.Java.lic”);
license.setLicense(in);
//set barcode license
com.aspose.barcode.License licBarcode = new com.aspose.barcode.License();
InputStream barLicence =
this.getClass()
.getClassLoader()
.getResourceAsStream(LICENSE_PATH + "Aspose.Total.Java.lic");
licBarcode.setLicense(barLicence);
//set pdf license
com.aspose.pdf.License pdfLicense = new com.aspose.pdf.License();
InputStream pdfLicenseInput =
this.getClass()
.getClassLoader()
.getResourceAsStream(LICENSE_PATH + "Aspose.Total.Java.lic");
pdfLicense.setLicense(pdfLicenseInput);
//set Cells license
com.aspose.cells.License licCells = new com.aspose.cells.License();
InputStream cellsLicense = this.getClass()
.getClassLoader()
.getResourceAsStream("doc-templates/" + "Aspose.Total.Java.lic");
licCells.setLicense(cellsLicense);
But while setting foor Bar code , I get Error. The License is not good for Barcode. I get the following error
java.lang.Exception: Failed to set license. Details: Failed to check license.
at com.aspose.barcode.License.setLicense(Unknown Source) ~[aspose-barcode-21.6.jar:21.6]
at gov.ca.lc.ls.arch.aspose.BaseDocGenerator.setLicence(BaseDocGenerator.java:332) [classes/:?]
at gov.ca.lc.ls.arch.aspose.BaseDocGenerator.createDocument(BaseDocGenerator.java:121) [classes/:?]
@nithiladaniel
The exception is thrown by Aspose.Barcode when the license file cannot be validated.
Typical reasons are:
- the license file that is being read is not the one that contains a Barcode entitlement (e.g. a trial file or a corrupted file);
- the file is read after it has already been consumed by a previous
setLicense call;
- the Barcode library version you are using is newer than the version for which the license was generated.
What to try
-
Verify the license file – open Aspose.Total.Java.lic in a text editor and confirm that it contains a <License> node with a <Product> entry for Barcode. If you only have a trial license, it will not contain that entry and the call will fail.
-
Load a fresh stream for each component (or use the overload that takes a file path).
// Barcode
com.aspose.barcode.License barcodeLic = new com.aspose.barcode.License();
barcodeLic.setLicense(
this.getClass().getClassLoader()
.getResourceAsStream(LICENSE_PATH + "Aspose.Total.Java.lic"));
// PDF
com.aspose.pdf.License pdfLic = new com.aspose.pdf.License();
pdfLic.setLicense(
this.getClass().getClassLoader()
.getResourceAsStream(LICENSE_PATH + "Aspose.Total.Java.lic"));
// Cells
com.aspose.cells.License cellsLic = new com.aspose.cells.License();
cellsLic.setLicense(
this.getClass().getClassLoader()
.getResourceAsStream(LICENSE_PATH + "Aspose.Total.Java.lic"));
If you prefer the path overload (no stream handling):
barcodeLic.setLicense("path/to/Aspose.Total.Java.lic");
-
Make sure all Aspose JARs are the same version (e.g., 21.6 for Barcode, PDF, Cells, etc.). Mixing different versions can cause the license validator to reject the file.
-
Test the license with a single component – comment out the PDF and Cells calls and run only the Barcode block. If it still fails, the problem is with the license file itself.
-
If the license is correct but the error persists, obtain a fresh license file from the Aspose customer portal (download the latest Aspose.Total.Java.lic) and replace the existing one.
What we need to confirm
- Exact versions of
aspose-barcode, aspose-pdf, and aspose-cells JARs you are using.
- Java runtime version (e.g., JDK 8, 11, 17).
- Whether the same license file works for the PDF and Cells components (you mentioned they load without error).
Provide the above details and, if possible, a minimal reproducible project (e.g., a Maven/Gradle sample) so we can verify the license handling on our side. If the issue turns out to be a defect, we will log it internally after we have a reproducible case.
@nithiladaniel,
It appears that you are using an older version of the Aspose for Java API (more than 2-3 years old) and are encountering issue while setting up your new license for Aspose.BarCode for Java.
Please note that newer licenses are signed with SHA256, whereas older licenses were signed with SHA1. A SHA256 license cannot be used with older API versions. If you already have an older license, you can continue using it with the older Aspose for Java API versions. Similarly, a newer license must be used with the newer API versions. This compatibility approach will always work.
We recommend you upgrading to the latest API versions, as they include numerous fixes and enhancements. However, if you still prefer to continue using the older API versions with new license, you can request an updated Java license signed with SHA1 (for free). To do so, you may contact the Sales team through the relevant forum or via email. The updated license will be compatible with both older and newer Aspose for Java API versions.
Please let us know if you need further assistance.