title: Read a Environment Variable in Java with Websphere
body: <p>I've a little problem with Websphere application server 7.0 (WAS7) and the reading of Environment Varaibles.</p>
  
  <p>With TomCat, I've defined a variable as </p>
  
  <pre><code>&lt;Environment name="myVar" type="java.lang.String" value="myVarOnServeur"
  </code></pre>
  
  <p>and I read it with a lookup on the initialContext :</p>
  
  <pre><code>Context ctx = new InitialContext();
  String myVar = (String) ctx.lookup( "java:comp/env/myVar" );
  </code></pre>
  
  <p>and it works!</p>
  
  <p>But with Websphere, I define a environment variable on the GUI but I can't read it in my java code. I've a NamingException.</p>
  
  <p><a href="https://i.stack.imgur.com/RpLYw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RpLYw.png" alt="enter image description here"></a><br>
  <sub>(source: <a href="http://fullahead.org/work/stackoverflow/was-environment-variables.png" rel="nofollow noreferrer">fullahead.org</a>)</sub>  </p>
  
  <p>How can I do to fix my problem?</p>