You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Andrew Watters <an...@gointernet.co.uk> on 2005/04/06 16:37:14 UTC

How to read JNDI resources?

Using tomcat 4.3.1 I have included the following in server.xml
<GlobalNamingResources>
    <Environment name="config_file" type="java.lang.String" value="test"/>
  </GlobalNamingResources>

In a servlet loaded on startup I try to read in the property
InitialContext ic = new InitialContext();
Context ctx = (Context) ic.lookup("java:comp/env");
String configFilename = (String)(ctx.lookup("config_file"));

This code throws a NamingException. Where have I gone wrong?

Thanks
Andrew

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: How to read JNDI resources?

Posted by Andrew Watters <an...@gointernet.co.uk>.
Thank you, I appreciate your reply. I didn't have a context entry so I 
added a minimal one (copied from the /examples one) before proceeding 
further as shown below.

        <Context path="/xxx" docBase="xxx" debug="0" reloadable="true" 
crossContext="true" />

Unfortunately tomcat doesn't start now. I get a 'Document base 
C:\Development\Java\jakarta-tomcat-4.1.31\webapps\xxx does not exist or 
is not a readable directory'

So I added a direcory xxx. Now tomcat starts ok but it doesn't unpack 
the xxx.war. Again I'm probably making some very simple mistake but 
can't see the problem or an answer in the docs or by googling...




Mark Thomas wrote:

> You need to include a <ResourceLink> element in your context.
>
> Mark
>
> Andrew Watters wrote:
>
>> Using tomcat 4.3.1 I have included the following in server.xml
>> <GlobalNamingResources>
>>    <Environment name="config_file" type="java.lang.String" 
>> value="test"/>
>>  </GlobalNamingResources>
>>
>> In a servlet loaded on startup I try to read in the property
>> InitialContext ic = new InitialContext();
>> Context ctx = (Context) ic.lookup("java:comp/env");
>> String configFilename = (String)(ctx.lookup("config_file"));
>>
>> This code throws a NamingException. Where have I gone wrong?
>>
>> Thanks
>> Andrew
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: How to read JNDI resources?

Posted by Mark Thomas <ma...@apache.org>.
You need to include a <ResourceLink> element in your context.

Mark

Andrew Watters wrote:
> Using tomcat 4.3.1 I have included the following in server.xml
> <GlobalNamingResources>
>    <Environment name="config_file" type="java.lang.String" value="test"/>
>  </GlobalNamingResources>
> 
> In a servlet loaded on startup I try to read in the property
> InitialContext ic = new InitialContext();
> Context ctx = (Context) ic.lookup("java:comp/env");
> String configFilename = (String)(ctx.lookup("config_file"));
> 
> This code throws a NamingException. Where have I gone wrong?
> 
> Thanks
> Andrew
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org