1

I'm preparing a servlet application and none of the properties file is getting loaded in application. Even though all the property files are residing in the same location.

enter image description here

Code:

Properties prop = new Properties();
        InputStream input = getClass().getClassLoader().getResourceAsStream("ldap.properties");;
         try{
                logger.debug("Loading Properties File");
                //input = new FileInputStream("ldap.properties");

                // load a properties file
                prop.load(input);
                logger.debug("Retry Count is: " +  Integer.parseInt(prop.getProperty("retry")));
                System.out.println("Retry Count is: " +  Integer.parseInt(prop.getProperty("retry")));
                logger.debug("downTimeValue is: " +  Integer.parseInt(prop.getProperty("downTimeValue")));
                retry = Integer.parseInt(prop.getProperty("retry"));
                downTimeValue = Integer.parseInt(prop.getProperty("downTimeValue"));

            } catch (IOException ex) {
                ex.printStackTrace();
            } finally {
                if (input != null) {
                    try {
                        input.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

Error:

[#|2018-01-22T15:34:27.313+0530|SEVERE|oracle-glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=64;_ThreadName=Thread-2;|log4j:WARN No appenders could be found for logger (com.amdocs.LDAPKit).|#]

[#|2018-01-22T15:34:27.314+0530|SEVERE|oracle-glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=64;_ThreadName=Thread-2;|log4j:WARN Please initialize the log4j system properly.|#]

[#|2018-01-22T15:34:27.314+0530|SEVERE|oracle-glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=64;_ThreadName=Thread-2;|log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.|#]

[#|2018-01-22T16:02:37.033+0530|WARNING|oracle-glassfish3.1.2|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=67;_ThreadName=Thread-2;|StandardWrapperValve[com.amdocs.LDAPKit]: PWC1406: Servlet.service() for servlet com.amdocs.LDAPKit threw exception
java.lang.NullPointerException
    at java.util.Properties$LineReader.readLine(Properties.java:434)
    at java.util.Properties.load0(Properties.java:353)
    at java.util.Properties.load(Properties.java:341)
    at com.amdocs.LDAPKit.doPost(LDAPKit.java:133)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
Abhishek
  • 640
  • 3
  • 19

1 Answers1

1

I highly recommend to transform your project to a maven project so that it will handle dependencies and build your project.

After that, move your properties files to resources folder because getClass().getClassLoader().getResourceAsStream("ldap.properties"); looks for files in resources folder.

Your project structure should look like this

enter image description here

hzitoun
  • 4,180
  • 30
  • 37