title: Tomcat JNDI lookup problem
body: <p>I was trying read a property value in Tomcat. My plan was to access the value using <code>System.getProperty("LOGPATH")</code> where <code>LOGPATH</code> is the name of my property.  However I did not find a way to set a System property value in Tomcat.</p>
  
  <p>Is there any way we can set a System property in Tomcat?</p>
  
  <p>As I did not get any documentation on setting the System property I thought of accessing the value using JNDI. So I added the following entry </p>
  
  <pre><code>&lt;Environment name="LOGPATH" type="java.lang.String" value="c:/temp" /&gt;
  </code></pre>
  
  <p>after </p>
  
  <pre><code>&lt;GlobalNamingResources&gt;
  </code></pre>
  
  <p>in <code>server.xml</code> file.</p>
  
  <p>The code I used for looking up the JNDI is </p>
  
  <pre><code>Context initCtx = new InitialContext();
  Context envCtx = (Context) initCtx.lookup("java:comp/env/");
  
  String path = (String) envCtx.lookup("LOGPATH");
  </code></pre>
  
  <p>When I executed the above code, I got the following error message.</p>
  
  <pre><code>javax.servlet.ServletException: Name LOGPATH is not bound in this Context
  org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
  org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
  </code></pre>
  
  <p>Then I added an entry in my web.xml </p>
  
  <pre><code> &lt;resource-env-ref&gt;
       &lt;resource-env-ref-name&gt;LOGPATH&lt;/resource-env-ref-name&gt;
   &lt;resource-env-ref-type&gt;java.lang.String&lt;/resource-env-ref-type&gt;
   &lt;/resource-env-ref&gt;
  </code></pre>
  
  <p>Now the error message is changed to </p>
  
  <pre><code>javax.naming.NamingException: Cannot create resource instance
  org.apache.naming.factory.ResourceEnvFactory.getObjectInstance(ResourceEnvFactory.java:99)
  </code></pre>
  
  <p>What am I doing wrong now? Thank you for the help.</p>