title: Access environmental parameters in web.xml from Web Service application
body: <p>I have to build <strong>two web service applications</strong> to be deployed to different servers (WebSphere 6.1). One of them is “linked” to another by calling its services, so the first web service application should be aware of the endpoint URL of the second one. </p>
  
  <p>Those applications are working in different environments: Dev, Test and Production.
  I have decided to store that URL as an environmental parameter in web.xml file of the first application to have some flexibility with moving them from one development stage to another, so the endpoint URL could be set during deployment.</p>
  
  <p>In web.xml of my first application I describe the environmental parameter as:</p>
  
  <pre><code>
  &lt;env-entry&gt;
  &lt;description&gt;Second WS&lt;/description&gt;
   &lt;env-entry-name&gt;SECOND_SVC_URL&lt;/env-entry-name&gt;
   &lt;env-entry-type&gt;java.lang.String&lt;/env-entry-type&gt;
   &lt;env-entry-value&gt;http//domain/url&lt;/env-entry-value&gt;
  &lt;/env-entry&gt; 
  </code></pre>
  
  <p>In the Java code I have:</p>
  
  <pre><code>
  Context initialContext = new InitialContext();
  Context context = (Context)initialContext.lookup("java:comp/env");
  Object o = context.lookup(“SECOND_SVC_URL”);
  …
  </code></pre>
  
  <p>I have got the exception on the second line of that code:</p>
  
  <pre><code>
  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
   at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:653)
   at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:257)
   at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:294)
   at javax.naming.InitialContext.lookup(InitialContext.java:361)…
  </code></pre>
  
  <p>Please, any help would be really appreciated.</p>
  
  <p>Thank you.</p>