I am trying out Aspose PDF for Java and I have encountered a problem. It seems that I need to load the license file every time I try to read a PDF file. i.e call setLicense in every class.
Is there any optimal way like load lic in static block across all classes in the application ?
Hi Mrinmoy,
Hi Tilal,
Thanks for your reply. But I am still not sure how to achieve this. First of all I didn’t understand what do you mean by “the license only needs to be set once per application/process”. What is application/process ? Are you referring to current thread ? Till now what I have manged to do is to initiate the license in a static block (as you said too) in a class and the functions of the class works very well.
But I need to initialize the license in Evey class that use Aspose.pdf, which is a not so good as I have to keep informing every developer to do so (I can create an abstract class but then every one need to extend that which is a similar problem)
I have used Aspose Cells before. What I used to do is to initiate the license in Application start-up (spring context initialization / or in any class that gets created during spring start-up) in a static block and it was effective for every class that use aspose cells. But now with Aspose PDF it’s not the same.
Note : I am not creating a class library
mrinmoy_chakraborty:
Thanks for your reply. But I am still not sure how to achieve this. First of all I didn't understand what do you mean by "the license only needs to be set once per application/process". What is application/process ? Are you referring to current thread ? Till now what I have manged to do is to initiate the license in a static block (as you said too) in a class and the functions of the class works very well.
But I need to initialize the license in Every class that use Aspose.pdf, which is a not so good as I have to keep informing every developer to do so (I can create an abstract class but then every one need to extend that which is a similar problem)
Application mean set of programs to achieve you specific goals/requirements. As you are using Aspose.Pdf for Java in your code so by "the license only needs to be set once per application/process" mean set license of Aspose.Pdf for Java once in start of your program before using any object of Aspose.Pdf for Java.mrinmoy_chakraborty:
I have used Aspose Cells before. What I used to do is to initiate the license in Application start-up (spring context initialization / or in any class that gets created during spring start-up) in a static block and it was effective for every class that use aspose cells. But now with Aspose PDF it's not the same.
Note : I am not creating a class library
If you are not creating some class library but web application then may apply the license in a start up servlet init() method using stream.public void init(ServletConfig config) throws ServletException {
super.init(config);
javax.servlet.ServletContext context = getServletContext();
License license = new License();
// getting license stream
InputStream resourceLic = context.getResourceAsStream("/Aspose.Pdf.Java.lic");
}Please feel free to contact us for any further assistance.Best Regards,