It works when running in a stand-alone java class, but when running in Apache Tomcat/8.0.41 (from an exploded WAR file), either from an embedded uuencoded license file or using a license file from the filesystem, I get the following exception:
[07-03 11:43:53] ERROR PdfUtil [documentTaskExecutor-1]: Failed to load Aspose license: Failed to set license. Details:
class com.aspose.note.system.exceptions.InvalidOperationException: Failed to set license. Details:
com.aspose.note.License.setLicenseInternal(Unknown Source)
com.aspose.note.License.setLicense(Unknown Source)
My usage is pretty simple:
static boolean licenseAdded;
private static String ASPOSE_LICENSE_FROM_FILE;
private static String ASPOSE_LICENSE = “SNIP”;
private static void license() {
if(!licenseAdded) {
License l = new License();
File licenseFile = new File("/license/Aspose.Note.lic");
if(licenseFile.exists())
ASPOSE_LICENSE_FROM_FILE = FileUtil.readFile(licenseFile).toString();
boolean fromFile = ASPOSE_LICENSE_FROM_FILE != null;
try (ByteArrayInputStream baos = new ByteArrayInputStream(fromFile ? ASPOSE_LICENSE_FROM_FILE.getBytes() : Base64.decodeBase64(ASPOSE_LICENSE))) {
log.error("Loading Aspose license from " + (fromFile ? “file(data length=” + ASPOSE_LICENSE_FROM_FILE.length() + “)” : “classFile”));
l.setLicense(baos);
licenseAdded = true;
log.error(“Aspose license loaded”);
} catch (Throwable t) {
log.error("Failed to load Aspose license: " + t.getMessage(), t);
}
}
}
public static File fromOneNote(File oneNoteFile, File target) throws IOException {
license();
oneNoteFile = oneNoteFile.getCanonicalFile();
log.debug(“fromOneNote: " + oneNoteFile + " to " + target);
log.debug(” target: " + target);
new Document(oneNoteFile.getCanonicalPath()).save(target.getCanonicalPath(), new PdfSaveOptions());
log.debug("target size: " + (target==null? “null” : (!target.exists() ? “does not exist” : target.length())));
return target;
}