title: naming exception with EJB
body: <p>I'm trying to follow an online tutorial and although I'm sure the writers of the tutorial know what they are doing, I keep getting an exception upon execution.</p>
  
  <p>Remote Interface</p>
  
  <pre><code>package com.tutorialspoint.stateless;
  
  import java.util.List;
  import javax.ejb.Remote;
  
  @Remote
  public interface LibrarySessionBeanRemote {
     void addBook(String bookName);
     List getBooks();
  }
  </code></pre>
  
  <p>Stateless EJB</p>
  
  <pre><code>package com.tutorialspoint.stateless;
  
  import java.util.ArrayList;
  import java.util.List;
  import javax.ejb.Stateless;
  
  @Stateless
  public class LibrarySessionBean implements LibrarySessionBeanRemote {
  
     List&lt;String&gt; bookShelf;    
  
     public LibrarySessionBean(){
        bookShelf = new ArrayList&lt;String&gt;();
     }
  
     public void addBook(String bookName) {
        bookShelf.add(bookName);
     }    
  
     public List&lt;String&gt; getBooks() {
        return bookShelf;
     }
  }
  </code></pre>
  
  <p>jndi.properties</p>
  
  <pre><code>java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
  java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
  java.naming.provider.url=localhost
  </code></pre>
  
  <p>tester</p>
  
  <pre><code>package com.tutorialspoint.test;
  
  import com.tutorialspoint.stateful.LibrarySessionBeanRemote;
  import java.io.BufferedReader;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.util.List;
  import java.util.Properties;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  
  public class EJBTester {
  
     BufferedReader brConsoleReader = null; 
     Properties props;
     InitialContext ctx;
     {
        props = new Properties();
        try {
           props.load(new FileInputStream("jndi.properties"));
        } catch (IOException ex) {
           ex.printStackTrace();
        }
        try {
           ctx = new InitialContext(props);            
        } catch (NamingException ex) {
           ex.printStackTrace();
        }
        brConsoleReader = 
        new BufferedReader(new InputStreamReader(System.in));
     }
  
     public static void main(String[] args) {
  
        EJBTester ejbTester = new EJBTester();
  
        ejbTester.testStatelessEjb();
     }
  
     private void showGUI(){
        System.out.println("**********************");
        System.out.println("Welcome to Book Store");
        System.out.println("**********************");
        System.out.print("Options \n1. Add Book\n2. Exit \nEnter Choice: ");
     }
  
     private void testStatelessEjb(){
  
        try {
           int choice = 1; 
  
           LibrarySessionBeanRemote libraryBean =
           LibrarySessionBeanRemote)ctx.lookup("LibrarySessionBean/remote");
  
           while (choice != 2) {
              String bookName;
              showGUI();
              String strChoice = brConsoleReader.readLine();
              choice = Integer.parseInt(strChoice);
              if (choice == 1) {
                 System.out.print("Enter book name: ");
                 bookName = brConsoleReader.readLine();
                 Book book = new Book();
                 book.setName(bookName);
                 libraryBean.addBook(book);          
              } else if (choice == 2) {
                 break;
              }
           }
  
           List&lt;Book&gt; booksList = libraryBean.getBooks();
  
           System.out.println("Book(s) entered so far: " + booksList.size());
           int i = 0;
           for (Book book:booksList) {
              System.out.println((i+1)+". " + book.getName());
              i++;
           }       
           LibrarySessionBeanRemote libraryBean1 = 
              (LibrarySessionBeanRemote)ctx.lookup("LibrarySessionBean/remote");
           List&lt;String&gt; booksList1 = libraryBean1.getBooks();
           System.out.println(
              "***Using second lookup to get library stateless object***");
           System.out.println(
              "Book(s) entered so far: " + booksList1.size());
           for (int i = 0; i &lt; booksList1.size(); ++i) {
              System.out.println((i+1)+". " + booksList1.get(i));
           }       
        } catch (Exception e) {
           System.out.println(e.getMessage());
           e.printStackTrace();
        }finally {
           try {
              if(brConsoleReader !=null){
                 brConsoleReader.close();
              }
           } catch (IOException ex) {
              System.out.println(ex.getMessage());
           }
        }
     }
  }
  </code></pre>
  
  <p>I get this exception:</p>
  
  <pre><code>javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
  null
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)
      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
      at javax.naming.InitialContext.init(InitialContext.java:244)
      at javax.naming.InitialContext.&lt;init&gt;(InitialContext.java:216)
      at test.EJBTester.&lt;init&gt;(EJBTester.java:33)
      at test.EJBTester.main(EJBTester.java:42)
  Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
      at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:340)
      at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:72)
      at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:61)
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:672)
      ... 5 more
  java.lang.NullPointerException
      at test.EJBTester.testStatelessEjb(EJBTester.java:56)
      at test.EJBTester.main(EJBTester.java:44)
  </code></pre>
  
  <p>your help will be very appreciated!
  D</p>