tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ondra Nekola <>
Subject Tomcat JNDI - mapping a String
Date Mon, 23 Feb 2004 10:12:51 GMT
I have developed a small web-based aplication. I use an ant build script 
to compile it and to generate a war. The application is used in several 
servers with different settings (it uses different databases, connects to 
different xml-rpc resources...) so it has to somehow read the 
configuration from the server environment. 
I have used the tomcat Web server administration tool to set Resources - a 
data source and several Environment Entries. The tool regenerates 
server.xml file in such a manner:

    <Environment description="" name="BLAH_USER" type="java.lang.String" 

Then I change my deployment descriptor get access to this environment:

The code, that tryes to read this environmnt looks like this:

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
String res_user = (String) envCtx.lookup("BLAH_USER");

The problem is, that I get this exception:
javax.naming.NamingException: Cannot create resource instance
        at org.apache.naming.factory.ResourceEnvFactory.getObjectInstance(
        at javax.naming.spi.NamingManager.getObjectInstance(
        at org.apache.naming.NamingContext.lookup(
        at org.apache.naming.NamingContext.lookup(
        at myapp.servlets.MyAppListener.contextInitialized(

When I try to access a mapped JDBC resource everything seems to be OK. 
When I list (NamingEnumeration enum = initCtx.list("java:comp/env");) the 
keys for mapped resources BLAH_USER appears.

I have tried look this situation in the Tomcat documentation and to google 
it, but I haven't get any reasonable idea to solve it.
   S pozdravem
       Ondrej Nekola
       ICQ# 160692888

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message