How to locate license file in the plugin code.

Certified Lead Developer

Hello,

I have developed a plugin which uses Aspose license.

The license file (Aspose.Words.lic) is copied under META-INF\lib\ directory. 

The license file reference is made using following code:

  license.setLicense("META-INF/lib/Aspose.Words.lic");

 

The plugin JAR contains the Aspose.Words.lic as part of it, however the plugin fails and it seems code is not able to locate the license file. 

Any pointers in this regard will be greatly appreciated.

 

Regards,

Abhay

  Discussion posts and replies are publicly visible

Parents Reply Children
  • 0
    Certified Lead Developer
    in reply to Justin Watts

    Using resource stream resolved the issue.

    Mentioning details below for the benefit of other people.

     

    Plugin code directory structure.

     

    Some Guidelines:

    1. Copy resource files under /resources directory at root.
    2. Directly refer resources under resources directory as shown in the code. e.g. "Aspose.Words.lic".
    3. Do not make any reference from Build Path, otherwise it will fail.
    4. Do not copy resource files under META-INF/lib/.

     

    The structure of plugin JAR after export will look like following

     

    Code for making reference to resource.

                         ClassLoader cl = Thread.currentThread().getContextClassLoader();

                         InputStream is = cl.getResourceAsStream("Aspose.Words.lic");

                         com.aspose.words.License license = new com.aspose.words.License();

                         license.setLicense(is);

                                            

                         if (license.isLicensed()) {

                               log.debug("License is Set");

                         }

                         else{

                               log.debug("License NOT Set");

                         }