title: How does the EJB client locate the EJB server without url?
body: <p>I am new to Java EE. At present I am going through <strong>The Java EE 6 Tutorial, Volume 1 (Basic Concepts Beta)</strong> by Sun Microsystems. To escape from monotonous reading time to time I play with few Java EE projects/codes written by others. </p>
  
  <p>I came from SE. My head is still filled with SE. In SE (<em>two tier</em> application) I use </p>
  
  <p><code>DATABASE_URL = "jdbc:mysql://something.db_server.com/db_name"</code></p>
  
  <p>This is how my client knows where the database server is. </p>
  
  <p>In one Java EE example I saw </p>
  
  <pre><code>// Access JNDI Initial Context.
  
  Properties p = new Properties();
  
  p.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
  p.put("java.naming.provider.url","jnp://localhost:1099");
  p.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
  
  InitialContext ctx = new InitialContext(p);
  
  // Change jndi name according to your server and ejb
  
  HelloRemote remote = (HelloRemote) ctx.lookup("HelloBean/remote");
  
  msg = "Message From EJB --&gt; " + remote.sayHello();
  </code></pre>
  
  <p>This I understand. The code has url and port number. There is this line</p>
  
  <pre><code>p.put("java.naming.provider.url","jnp://localhost:1099");
  </code></pre>
  
  <p>Client side knows where is the server by the url and which port to knock. I think the code was written at the time of Java EE 5.</p>
  
  <p>Today I have found another example where Netbeans 7, Java EE 6, and GlassFish 3 are used. The client side code </p>
  
  <pre><code>@EJB
  private static MySessionRemote mySession;
  
  /**
   * @param args the command line arguments
   */
  
  public static void main(String[] args) {
      JOptionPane.showMessageDialog(null, 
              "result = " + mySession.getResult());
  }
  </code></pre>
  
  <p>Here is the link
  <a href="http://netbeans.org/kb/docs/javaee/entappclient.html" rel="noreferrer">http://netbeans.org/kb/docs/javaee/entappclient.html</a></p>
  
  <p>No url and port number are given. </p>
  
  <p><strong>Java EE 6 Development with Netbeans 7</strong> by David R. Heffelfinger has a similar example in chapter 7. The author did not explain how it is done in the book. I think he has done it but I probably missed it…</p>
  
  <p>My question is how the client side locate the server without url? Is it stated in one of those xml files? Client can be in California and the GlassFish Server can be in New York.  Can anyone explain it to me or point to any tutorial/blog/article where I can find the answer?</p>
  
  <p>Thank you. </p>