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
Hi Mrinmoy,
Thanks for your feedback.
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 managed to do is to initiate the license in a static block (as you said too) in a class and the functions of the class work very well. But I need to initialize the license in Every class that uses Aspose.pdf, which is not so good as I have to keep informing every developer to do so (I can create an abstract class but then everyone needs to extend that which is a similar problem).
Application means a set of programs to achieve your 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” means set the license of Aspose.Pdf for Java once at the 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 uses 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 a web application then you may apply the license in a start-up servlet init() method using streams.
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,