title: Changing embedded Tomcat from v6 to v7 causes InitialContext lookup to fail
body: <p>I'm using JUnit test cases to exercise my web service using embedded Tomcat. Under Tomcat 6 everything was working fine, but when I switched my project to Tomcat 7 I'm coming unstuck.</p>
  <p>The test code to setup the embedded Tomcat server is as follows:</p>
  <h3>Tomcat 6</h3>
  <pre><code>Embedded container = new Embedded();
  container.setCatalinaHome(&quot;C:\\Program Files\\Apache Software Foundation\\Tomcat 7.0.11&quot;);
  container.setRealm(new MemoryRealm());
  container.setName(&quot;Catalina&quot;);
  Engine engine = container.createEngine();
  container.addEngine(engine);
  Host host = container.createHost(&quot;localhost&quot;, &quot;/DecoderServiceTest&quot;);
  Context rootContext = container.createContext(&quot;/DecoderServiceTest&quot;, System.getProperty(&quot;user.dir&quot;) + &quot;/build/web&quot;);
  host.addChild(rootContext);
  engine.setName(&quot;Catalina&quot;);
  engine.addChild(host);
  engine.setDefaultHost(&quot;localhost&quot;);
  container.addEngine(engine);
  Connector connector = container.createConnector(InetAddress.getLocalHost(), 4321, false);
  container.addConnector(connector);
  container.start();
  </code></pre>
  <p>As the embedded API has changed between versions 6 and 7, I've changed my own code to the following:</p>
  <h3>Tomcat 7</h3>
  <pre><code>Tomcat tomcat = new Tomcat();
  tomcat.setBaseDir(&quot;C:\\Program Files\\Apache Software Foundation\\Tomcat 7.0.11&quot;);
  tomcat.setPort(1234);
  tomcat.addWebApp(&quot;/DecoderServiceTest&quot;, System.getProperty(&quot;user.dir&quot;)+&quot;/build/web&quot;);
  tomcat.setHostname(&quot;localhost&quot;);
  tomcat.start();
  </code></pre>
  <p>The actual web service starts up fine when I execute the JUnit test (I can use my web browser and see the WSDL being served up).</p>
  <p>However, in the constructor of my web service I intialise some variables based on the values in the <code>web.xml</code> file (which is located in <code>System.getProperty(&quot;user.dir&quot;)+&quot;/build/web/WEB-INF/web.xml&quot;</code>), as follows:</p>
  <pre><code>  Context initCtx = new InitialContext();
    Context envCtx = (Context) initCtx.lookup(&quot;java:comp/env&quot;);
    int thumbnailSize = (Integer) envCtx.lookup(&quot;thumbnail-pixel-size&quot;);
  </code></pre>
  <p>Where my <code>web.xml</code> file contains the following entry:</p>
  <pre><code>&lt;env-entry&gt;
    &lt;env-entry-name&gt;thumbnail-pixel-size&lt;/env-entry-name&gt;
    &lt;env-entry-type&gt;java.lang.Integer&lt;/env-entry-type&gt;
    &lt;env-entry-value&gt;64&lt;/env-entry-value&gt;
  &lt;/env-entry&gt;
  </code></pre>
  <p>When I try and create the <code>envCtx</code> object I get a <a href="http://download.oracle.com/javase/1.5.0/docs/api/javax/naming/NamingException.html" rel="nofollow noreferrer">NamingException</a> with the message that <code>Name java:comp is not bound in this Context</code>. I'm confused because it worked fine with Tomcat 6. Have I missed something in the setup of Tomcat 7 that I had previously defined in the setup of Tomcat 6?</p>