Free Support Forum - aspose.com

Aspose.Words licensing problem in java web application

I’m trying to use Aspose.Words within a java web application but it is not finding the license file Aspose.Words.lic.

I have followed the licensing code examples in the Aspose help and have put my Aspose.Words.lic file into the same dir as my Aspose.Words.jdk15.jar, i.e. the WEB-INF/lib directory of my web application.

If I use no path in the call to license.setLicense(“Aspose.Words.lic”) then it fails. If I put in an absolute path, then it works fine. But I can’t use an absolute path because I don’t know the location the app will be installed in.

Here’s my code:
com.aspose.words.License license = new com.aspose.words.License();

try {
log.debug(“Applying license for Aspose.Words”);
license.setLicense(“Aspose.Words.lic”);
log.debug(“Successfully applied license for Aspose.Words”);
}
catch (Exception e) {
log.error("There was an error applying the license for Aspose.Words: " + e);
}



Document doc = new Document(… … … );

The exception code is always hit.

After some more investigation using the SysInternals File Monitor on Windows 2000, the Aspose.Words is firstly looking in the current directory - which is the main directory of Tomcat, and this fails because the license is below that, within my web application.
Secondly, Aspose.Words checks the WEB-INF/lib directory - but if the path contains a space, this space appears to be translated to a %20 by Aspose.Words (i.e. C:\Program%20Files…) which fails with a Path Not Found error.

I’ve had this problem on both Windows 2000 Pro and Mandriva Linux 2007.1 using both Jetty and Tomcat as servlet containers. I’m using Sun Java 5 and 6.

Do you have any suggestions?

Thanks,
Paul

Hi, Paul,

Yes, it’s my very old todo to change from File to URL when loading license by name… I have raised the todo’s level to fix it in a nearest release.

For workaround you can use code from ours Web demo project (demos\Aspose.Words.Demos.Web\src\DemoServlet.java):

String webAppDir = this.getServletContext().getRealPath("/");

File licenseFile = new File(webAppDir, "WEB-INF/Aspose.Words.Java.lic");

license.setLicense(licenseFile.getAbsolutePath());

Best regards,

Hi Konstantin,

Thanks for your help - I also arrived at a similar workaround.
By the way, for this to work with the Aspose library in the lib directory, the code needs to be like this:

String webAppDir = this.getServletContext().getRealPath("/");
File licenseFile = new File(webAppDir, “WEB-INF/lib/Aspose.Words.lic”);
license.setLicense(licenseFile.getAbsolutePath());

(note the change to the license file name and path)

Best wishes,
Paul