1 Reply Latest reply on May 8, 2008 8:24 AM by Nicklas Karlsson

    Application Settings read at startup

    scott duke Novice

      Currently, I have a class which is read during startup. It reads the information fine.

      public class PropertyInfo implements PropertyInfoLocal, Serializable  {
           Log log;
           @PersistenceContext(type = EXTENDED)
           EntityManager em;
           private String tmpDir;
           public void initialize() {
                String fileSep = System
                String homeDir = System
                String dukeProperty = homeDir + fileSep + "deploy" + fileSep
                          + "artwork.ear" + fileSep + "artwork.war" + fileSep + "WEB-INF"
                          + fileSep + "configuration.properties";
                log.info("configuration Properties [#0]", dukeProperty);
                Properties props = new Properties();
                try {
                     FileInputStream fis = new FileInputStream(dukeProperty);
                     String tmpDir = props.getProperty("tmp.dir");
                     System.out.println(" ");
                     System.out.println("tmpDir --->> " + tmpDir);
                     System.out.println(" ");
                } catch (FileNotFoundException ex) {
                     log.error("The 'configuration.properties' file is missing.");
                } catch (IOException ex) {
                     log.error("Unable to read the 'configuration.properties' file.");

      The problem is when I try to read this information from within another class. I have tried both:

      PropertyInfo targetDir = (PropertyInfo) Contexts.getApplicationContext().get("propertyInfo");


      PropertyInfo pi = (PropertyInfo) Component.getInstance(PropertyInfo.class);

      These give me a classCastException.

      Could someone tell me what I am doing wrong? Is there a better way of handling application settings?