title: How to connect to WebSphere in J2EE client environment?
body: <p>I'm trying to connect to <strong>EJB</strong> on <strong>WebSphere 7.0</strong>. The EJB requires <code>javax.ejb.SessionContext</code> and reads Principal from it, so I need to log in before calling it.</p>
  
  <p>I'm using the following code in stand-alone application:</p>
  
  <pre><code>import javax.naming.InitialContext;
  import javax.security.auth.login.LoginContext;
  import com.ibm.websphere.security.auth.WSSubject;
  import com.ibm.websphere.security.auth.callback.WSCallbackHandlerImpl;
  
   public static void main(String[] args) throws Exception {
      InitialContext ic = new InitialContext(System.getProperties());
      LoginContext lc = new LoginContext("WSLogin",
          new WSCallbackHandlerImpl("myuser","mypass"));
      lc.login();
      WSSubject.setRunAsSubject(lc.getSubject());
      SessionContext sessionContext=(SessionContext) ic.lookup(
          "java:comp/env/sessionContext");
  }
  </code></pre>
  
  <p>I've added the entry to my <code>jmxremote.access</code>:</p>
  
  <blockquote>
    <blockquote>
      <p>myuser readwrite</p>
    </blockquote>
  </blockquote>
  
  <p>However, I get an exception:</p>
  
  <blockquote>
    <p>Caused by: javax.naming.ConfigurationException: Name space accessor
    for the java: name space has not been set. Possible cause is that the
    user is specifying a java: URL name in a JNDI Context method call but
    is not running in a J2EE client or server environment.    at
    com.ibm.ws.naming.java.javaURLContextFactory.isNameSpaceAccessable(javaURLContextFactory.java:98)
      at
    com.ibm.ws.naming.urlbase.UrlContextFactory.getObjectInstance(UrlContextFactory.java:82)
      at
    javax.naming.spi.NamingManager.getURLObject(NamingManager.java:584)
      at
    javax.naming.spi.NamingManager.getURLContext(NamingManager.java:533)
      at
    javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:320)
      at javax.naming.InitialContext.lookup(InitialContext.java:392)</p>
  </blockquote>
  
  <p>What else should I do, to run my code in the 'J2EE client environment' mentionend in the error message?</p>