title: JNDI lookup is not happening when we bind object in one project and look up from second
body: <p>I have two java projects, <code>Test1</code> and <code>Test2</code>, in <code>Test1</code> project I have a servlet with the below code </p>
  
  <pre><code>InitialContext initialContext=new InitialContext();
  Class.forName("com.mysql.jdbc.Driver");
  Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/lntdb","root","root");
  initialContext.bind("conn", connection);
  response.getWriter().println("Bound to JNDI "+initialContext.lookup("conn"));`
  </code></pre>
  
  <p>the above code is binding <code>MYSQL</code> database connection object to <code>JNDI</code> with name <code>conn</code>, then from <code>Test2</code> project I am trying to retrieve the connection object. <code>Test2</code> also having a servlet with below code</p>
  
  <pre><code>InitialContext initialContext=new InitialContext();
  response.getWriter().println(initialContext.lookup("java:comp/env/conn"));
  </code></pre>
  
  <p>But I am getting exception the stack trace is below</p>
  
  <blockquote>
    <p>javax.naming.NameNotFoundException: Name [conn] is not bound in this Context. Unable to find [conn].
        at org.apache.naming.NamingContext.lookup(NamingContext.java:820)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
        at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
        at javax.naming.InitialContext.lookup(Unknown Source)
        at com.lnt.TestServlet.doGet(TestServlet.java:19)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    `</p>
  </blockquote>
  
  <p>Could you tell what is wrong in my code and why I am not able to retrieve connection object</p>