Search code examples
jdeveloper

Where to put properties file in jDeveloper IDE and how to access it in Java class


I have been using jDeveloper IDE Build JDEVADF_12.1.3.0.0_GENERIC_140521.1008.S. My project consist of SOAP based web services. All looks good. My project is running fine. However there is a requirement from client for properties file.

I tried to create folder at various places and even placed .properties file directly in the package and tried to fetch values from it using below code.

        /* First try of fetching from properties file*/

        InputStream is = CountryRepositoryDao.class.getClassLoader().getResourceAsStream("bundle.properties");
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("bundle.properties");
        Properties prop = new Properties();
        prop.load(is);
        System.out.println(prop.getProperty("surname"));

        /* Second try of fetching properties file */
        ClassLoader loader = ClassLoader.getSystemClassLoader ();
        InputStream oInputStream = loader.getResourceAsStream ("config.properties");
        Properties m_Properties = new Properties();
        m_Properties.load(oInputStream);
       System.out.println(m_Properties.getProperty("surname"));

However I am getting Null pointer exception ! I tried every tricks in the box but no luck.

could you guys please help me.

Thanks, Kailash


Solution

  • I have resolved the issue. I did following.

    InputStream  adf = 
    CountryRepositoryDao.class.getClassLoader().
    getResourceAsStream("com/ge/fcm/dao/app.properties");
    
    Properties prop = new Properties();
    prop.load(adf);
    System.out.println(prop.getProperty("surname")); //I am getting the value.
    

    There was an issue with the path in the parameter of getResourceAsStream.

    Thanks, Kailash