1 Reply Latest reply on Sep 1, 2010 9:53 AM by Michael.Imhoff

    How to refer the resouce files in Custom component jars

    Muni raj Level 1

      hi,

       

      I developed a simple test custom component which would return a string read from a properties file. The jar file was packed with the properties file. When executed in Eclipse, the property was read sucessfully. But when the jar file was deployed as service in Livecycle it is throwing null pointer exception. It is unable to read the properties file inside the jar(I had the properties file in two paths inside the jar --

      1.at the root along with the component.xml file.

      2. under the same folder as that of the class file)

       

      Below is the code snippet with methods to read the properties file in both the locations

       

      public String getPropertyInSamepath() throws IOException{
               ClassLoader classLoader = Thread.currentThread().getContextClassLoader();       
               InputStream propStream  = classLoader.getResourceAsStream("org/resources/resource.properties");              
               Properties props = new Properties();
               props.load( propStream );
              return props.getProperty("message");
          }
          public String getPropertyInRoot() throws IOException{
               ClassLoader classLoader = Thread.currentThread().getContextClassLoader();       
               InputStream propStream  = classLoader.getResourceAsStream("resource.properties");            
               Properties props = new Properties();
               props.load( propStream );
              return props.getProperty("message");
          }

       

      Livecycle is failing to read both the properties file inside the jar file. Do I need to add any entries to the component.xml file? Please suggest.

       

      Same issue came when I tried to have hibernate as a custom component.. LC was unable to read the config files.. It threw the error org.hibernate.HibernateException: /hibernate.cfg.xml not found although the xml file was there inside the jar file.

       

      Please suggest a way by which the custom component can refer to the resource files inside the jar.

       

      Thanks,

      Muniyaraj

        • 1. Re: How to refer the resouce files in Custom component jars
          Michael.Imhoff

          Here is an example of what I normally use:

           

          package com;

           

          import java.util.MissingResourceException;

          import java.util.ResourceBundle;

           

          import com.CustomSystemException;

           

          public class AppProperties {

           

          private static final String BUNDLE_NAME = "app";

          private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);

           

          private AppProperties {

          }

           

          public static String getString(String key) {

          try {

          return RESOURCE_BUNDLE.getString(key);

          } catch (MissingResourceException e) {

          throw new CustomSystemException("Missing bundle key:" + key, e);

          }

          }

          }

           

          Hope this helps,

          Michael