Licence Issue Java 1.4

Hi friends,

I’m using Aspose.Words.jdk14.jar in a web application running under Tomcat. This jar is located into the lib directory of my application and there also I pasted the licence file Aspose.Custom.lic

So, before I use any Document instance I called the next method :

private void loadLicense() throws Exception{
    License license = **new** License();
    license.setLicense("Aspose.Custom.lic");//throws exception
}

the second line of method throws an Exception: java.lang.Exception: Cannot find license ‘Aspose.Custom.lic’.

I did a second test moving the licence file to C:\ and also changing the line code to :

license.setLicense("C:\\Aspose.Custom.lic");//NO exception

This way works.

How can I do to get the licence file from my application directoy?

Hi,

Strange, one of my test configurations is exactly as your one and all works fine. May be Tomcat loads your application from another folder? May be some old configuration still remains in Tomcat’s cashes…

Please, try this code:

Class clazz = License.class;

String classFileShortPath = “/” + clazz.getName().replace(’.’, ‘/’) + “.class”;

URL resource = clazz.getResource(classFileShortPath);

System.out.println("resource = " + resource);

You should get something like:

resource = jar:file:/<>/Aspose.Words.jdk14.jar!/com/aspose/words/License.class

And, please, check are jar and license dirs equal?

Best Regards,

Hi, I did test you mentioned. Here the print lines:

resource = jar:file:/C:/Archivos%20de%20programa/apache-tomcat-5.5.25/webapps/au
thor/WEB-INF/lib/Aspose.Words.jdk14.jar!/com/aspose/words/License.class
java.lang.Exception: Cannot find license 'Aspose.Custom.lic'.

I double check and yes jar and licence dir are equal: C:/Archivos%20de%20programa/apache-tomcat-5.5.25/webapps/author/WEB-INF/lib/

another suggestion?

Hi,

The last test works as expected in your environment. So we have to try more verbose test. But first of all, please, reload your Tomcat and check are you using the last Aspose.Words release. Here is the code:

//get the container (jar file or ‘classes’ dir).

Class clazz = License.class;

String classFileShortPath = “/” + clazz.getName().replace(’.’, ‘/’) + “.class”;

String classFileFullPath = clazz.getResource(classFileShortPath).toString();

int classStart = classFileFullPath.length() - classFileShortPath.length();

String container = classFileFullPath.substring(0, classStart);

System.out.println("container = " + container);

**

//get the folder, that holds the container:

//strip protocol from the beginning of the string and jar file or a ‘classes’ dir from the end.

int startPos = container.indexOf(’/’) + 1;

int endPos = container.lastIndexOf(’/’);

String folder = container.substring(startPos, endPos);

System.out.println("folder = " + folder);

//load the license.

String licenseName = “Aspose.Custom.lic”;

File licenseFile = new File(folder, licenseName);

if (licenseFile.exists())

{

FileInputStream licenseStream = new FileInputStream(licenseFile);

System.out.println("licenseStream loaded OK = " + licenseStream);

}

else

{

System.out.println(“Can’t find license file!”);

}

Please, inform me what you get from that test.

Best Regards,

This is my application prints:

container = jar:file:/C:/Archivos%20de%20programa/apache-tomcat-5.5.25/webapps/author/WEB-INF/lib/Aspose.Words.jdk14.jar!
folder = C:/Archivos%20de%20programa/apache-tomcat-5.5.25/webapps/author/WEB-INF/lib
Can't find license file!

I previously download the last Aspose.Words release: Aspose.Words.Java.2.4.2

Hi Konstantine, I previously posted my results using Apache Tomcat. I did the same test but now over IBM Webshepre and the print lines here are:

container:wsjar:file:/C:/opt/IBM/WebSphere/AppServer/profiles/app1/installedApps/dmgrCell/ManagerGateway.ear/author.war/WEB-INF/lib/Aspose.Words.jdk14.jar!
folder:C:/opt/IBM/WebSphere/AppServer/profiles/app1/installedApps/dmgrCell/ManagerGateway.ear/author.war/WEB-INF/lib
licenseStream loaded OK = java.io.FileInputStream@4e525162

So that means that license file was loaded successfull right?, but my output is still truncated and a legend also is there:

This document was truncated here because it was created using Aspose.Words in Evaluation Mode.

Apache Tomcat version I was using is apache-tomcat-5.5.25 that runs over java 1.5

WebSphere version is 6.0 and runs over java 1.4

Both must be supported by ASPOSE Word but seems not.

Hi,

Sorry for delay. The last test code doesn’t loads the license – it is just a simplified emulation how Aspose.Words finds the license file in the “root” dir. So, what we have after these tests.

  1. Tomcat. The file with ‘licenseName’ name doesn’t exist in the folder named ‘folder’ OR it can’t be opened from under Tomcat because of security reasons. – Please, check your Tomcat configuration, file name and “root” folder.

  2. WebSphere. Aspose.Words can locate and open the license file as a stream. You just have to use setLicense() as usual to set the license.

Any way you have to know that Aspose.Words does support Tomcat and WebSphere – we just have to locate what is wrong with configuration of your environment.

Regards,

Finally it loads correctly the licence file. Thanks for your help.

Unfortunatelly now I’m dealing now with an issue when I create a com.aspose.words.Document (still Websphere 6 ) . Actually, it works great under tomcat (i used tomcat 5.5 for development as I said above), but when I deploy the EAR file to Websphere, it throws me an com.aspose.words.FileCorruptedException trying to open ANY word file (.doc not .docx…i’ve tried with even a simple text word file with no luck…)

Append the code where it fails…

I’ve tried this

Document doc = new Document(file.getAbsolutePath());

And this

Document doc = new Document(file.getAbsolutePath(),LoadFormat.DOC,null);

And this…

FileInputStream is = new FileInputStream(new File(file.getAbsolutePath()));
Document doc = new Document(is);

And the exception is

[8/11/08 17:16:21:177 EDT] 0000001d SystemErr R com.aspose.words.FileCorruptedException: The document appears to be corrupted and cannot be loaded.
at com.aspose.words.Document.a(Unknown Source)
at com.aspose.words.Document.a(Unknown Source)
at com.aspose.words.Document.(Unknown Source)
at com.aspose.words.Document.(Unknown Source)

Thanks in advance