title: javax.naming.NoInitialContextException: while running JUNIT test cases in webservices
body: <p>I have JNDI config for all possible database connectivity in my application. Meanwhile I am using JUNIT to test my applications. I find successful connection form my webservices class invocation but error throws while calling it through junit test class.</p>
  
  <p>My JNDI setting is </p>
  
  <pre><code>public static Connection getConnectionPool() {
      Connection conn = null;
  System.out.println("Creating connection pool.");
      try {
          Context initContext = new InitialContext();
          Context envContext  = (Context)initContext.lookup("java:/comp/env");
          DataSource ds = (DataSource)envContext.lookup(getJNDIName());
          conn = ds.getConnection();
      } catch (SQLException e1) {
          e1.printStackTrace();
      } catch (NamingException e) {
          e.printStackTrace();
      }
      return conn;
  
  }
  
  private static String getJNDIName()
  {
      if(!readJNDI)
      {
          try{
              Properties prop = new Properties();
              prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("config.properties"));
              JNDIName = prop.getProperty("jndi.name");
              System.out.println("JNDIName : "+JNDIName);
              readJNDI = true;
          }catch(Exception ex){
              ex.printStackTrace();
          }
      }
      return JNDIName;
  }
  </code></pre>
  
  <p>Below mentioned is the  error.</p>
  
  <blockquote>
    <p>javax.naming.NoInitialContextException: Need to specify class name in
    environment or system property, or as an applet parameter, or in an
    application resource file:  java.naming.factory.initial</p>
  </blockquote>
  
  <p>How do I resolve it.?</p>
  
  <p>Thanks in advance.</p>