> 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:
> 
> <Server>
> ...
>   <GlobalNamingResources>
>     <Environment description="" name="BLAH_USER" type="java.lang.String" 
> value="MrSpock"/>
> ...
>   </GlobalNamingResources>
> ...
> </Srver>
> 
> Then I change my deployment descriptor get access to this environment:
> <web-app>
> ...
>   <resource-env-ref>
>     <resource-env-ref-name>BLAh_USER</resource-env-ref-name>
>     <resource-env-ref-type>java.lang.String</resource-env-ref-type>
>   </resource-env-ref>
> ...
> </web-app>
> 
> 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(ResourceEnvFactory.java:146)
>         at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:301)
>         at org.apache.naming.NamingContext.lookup(NamingContext.java:837)
>         at org.apache.naming.NamingContext.lookup(NamingContext.java:197)
>         at myapp.servlets.MyAppListener.contextInitialized(MyAppListener.java:123)
> 
> 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.

I have done some other tests and I can't find the right solution. Stop me, 
when I become wrong:
1) Enteries in <GlobalNamingResources> are accesible for the whole 
server including all deployed applications.
2) When I include <Environment> element into <GlobalNamingResources> a new 
Environment variable should be accessible in all applications. It should 
do the same thing as adding <env-entry> into web.xml, that works for me.
3) The defined variable appears in the JNDI namespace of an application, 
when it's mapped into it by specifiing <resource-env-ref> in web.xml.
4) I appears as java:comp/env/VAR_NAME.
5) There should'n be no problem for Tomcat to construct instances of 
java.lang.String or java.lang.Integer.
-- 
   S pozdravem
       Ondrej Nekola
       [EMAIL PROTECTED]
       http://www.matfyz.cz/ondra
       ICQ# 160692888

PS: My environment - windows2k, JDK 1.4.2 and 1.5.0 beata, Tomcat 5.0.16, 
5.0.18 and 4.1.27.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to