Set license as stream/embed in JAVA while exporting as JAR

Hi team,

Requesting a solution to embed .lic file into JAR while exporting rather than adding path to the source code. Kindly reply asap.

Regards
Priyadharshini

@priyadharshini,

You can simply copy the .lic file in the resources folder of your project. Rebuilding the project should embed the .lic file into application’s .jar file. After that you can apply license by using the code like below:

License lic = new License();
lic.setLicense(Program.class.getResourceAsStream("Aspose.Total.Java.lic"));

For example, please check this article:
[How to embed resource files in your jars using Netbeans](https://capturevision.wordpress.com/2008/06/28/how-to-embed-resource-files-using-netbeans/)

@awais.hafeez ,

Thank you for update.

Meanwhile, we are currently working on a workaround where libraries

  • Words

  • Cells

  • Slides

  • PDF

all are embedded into a single JAR. But, Slides and Cells package is not getting licensed even though we have Aspose,total.Java.lic .
Kindly, help us fix this bug.

Regards
Priyadharshini

@Vadivel_S_S,

I have observed your following comments.

Can you please share the detailed requirements along with a scenario what what you are trying to achieve and what issue you are facing on your end. I would also request you to please share a working sample project reproducing the issue on your end as well.

@Vadivel_S_S

Thanks for using Aspose APIs.

For Aspose.Cells. please use the following code as shared by @awais.hafeez in his post. i.e.

Please remember, there are separate License classes for Aspose.Words and Aspose.Cells.

These classes are as follows

  • com.aspose.words.License
  • com.aspose.cells.License

So your code for Aspose.Cells will look like this.

Java

com.aspose.cells.License lic = new com.aspose.cells.License();
lic.setLicense(Program.class.getResourceAsStream("Aspose.Total.Java.lic"));

Thank you @awais.hafeez.
It’s working now!

Regards
Priyadharshini

Hi,
I am facing similar issue, I tried with resourceAsStream, but I am getting evaluation Warning, when I use “license.setLicense(“Aspose.Total.Java.lic”);” it is working fine when run as application from IDE, but getting error “Cannot find license file: Aspose.Total.Java.lic” when running as jar

@hakim.mitm,

Which specific Aspose for Java APIs you are using? Have you copied the “Aspose.Total.Java.lic” file into respective folder? You may copy the “Aspose.Total.Java.lic” file into the resources folder of your project. Rebuild the project to embed the license file into your application’s .jar file. After that you can apply license in code like below:

License license = new License();
lic.setLicense(Program.class.getResourceAsStream("Aspose.Total.Java.lic"));

In case, you still find the issue, kindly share a working sample project reproducing the issue on our end. Please do not include license file into your project. We will check your issue soon.

Yes I have kept license file in resource folder and if I use above steps to set license it gives Evaluation Warning, if use setlicense(“Aspose.Total.lic”) then it works fine with Intellij Idea run as application but when I create jar it says Cannot find license file

@hakim.mitm,

Which Aspose for .NET API/library (which version) you are using?

Please make sure you have placed the licensing code at a place in code which it should be processed at the start of your application and before using any other Aspose .NET APIs. As requested, kindly share a sample project (without your license file) reproducing the issue on our end.

Ignore it is working I have used ClassLoader to load license file.
Thanks

@hakim.mitm,

Good to know that your issue is sorted out now. Please feel free to write back to us if you have any further queries or comments.