Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with JNDI initial context

Status
Not open for further replies.

andfer

Programmer
May 17, 2002
1
0
0
IT
We have two context defined in server.xml. The code for the two applications is the same.
In a class that implements ServletContextListener we try to use InitialContext but in the second context (docbase=./autobid) tomcat throws an exception:
javax.naming.NameNotFoundException: Name java: is not bound in this Context while in the first application (docbase=./portale) there's no problem.
What is the difference between the two context?
Thanks for the collaboration,

Danilo & Andrea

Here's the stack trace for the exception:

javax.naming.NameNotFoundException: Name java: is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:811)
at org.apache.naming.NamingContext.lookup(NamingContext.java:194)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at it.marconimobile.businessapplication.portale.sql.InitializeDbProperties.contextInitialized(InitializeDbProperties.java:89)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3250)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3524)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:738)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:347)
at org.apache.catalina.core.StandardService.start(StandardService.java:497)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:2189)
at org.apache.catalina.startup.Catalina.start(Catalina.java:510)
at org.apache.catalina.startup.Catalina.execute(Catalina.java:400)
at org.apache.catalina.startup.Catalina.process(Catalina.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:203)


Here's the portion of code:

try {
Context ctx = (Context) new InitialContext().lookup("java:/comp/env");
}
catch (NamingException ex) {
context.log("ERROR");
ex.printStackTrace();
}


Here'a portion of our server.xml file:

<Context className=&quot;org.apache.catalina.core.StandardContext&quot; cachingAllowed=&quot;true&quot; charsetMapperClass=&quot;org.apache.catalina.util.CharsetMapper&quot; cookies=&quot;true&quot; crossContext=&quot;false&quot; debug=&quot;5&quot; displayName=&quot;Application 1&quot; docBase=&quot;./portale&quot; mapperClass=&quot;org.apache.catalina.core.StandardContextMapper&quot; path=&quot;/portale&quot; privileged=&quot;false&quot; reloadable=&quot;false&quot; swallowOutput=&quot;false&quot; useNaming=&quot;true&quot; wrapperClass=&quot;org.apache.catalina.core.StandardWrapper&quot;>
<Logger className=&quot;org.apache.catalina.logger.FileLogger&quot; debug=&quot;9&quot; directory=&quot;logs&quot; prefix=&quot;localhost_portale.&quot; suffix=&quot;.txt&quot; timestamp=&quot;true&quot; verbosity=&quot;4&quot;/>
<Resource name=&quot;jdbc/conn1&quot; auth=&quot;Container&quot; scope=&quot;Shareable&quot; type=&quot;javax.sql.DataSource&quot;/>
<Resource name=&quot;jdbc/conn2&quot; auth=&quot;Container&quot; scope=&quot;Shareable&quot; type=&quot;javax.sql.DataSource&quot;/>
<Resource name=&quot;jdbc/conn3&quot; auth=&quot;Container&quot; scope=&quot;Shareable&quot; type=&quot;javax.sql.DataSource&quot;/>
<Resource name=&quot;jdbc/conn4&quot; auth=&quot;Container&quot; scope=&quot;Shareable&quot; type=&quot;javax.sql.DataSource&quot;/>
<Resource name=&quot;jdbc/conn5&quot; auth=&quot;Container&quot; scope=&quot;Shareable&quot; type=&quot;javax.sql.DataSource&quot;/>
<ResourceParams name=&quot;jdbc/conn1&quot;>
...
</ResourceParams>
<ResourceParams name=&quot;jdbc/conn2&quot;>
...
</ResourceParams>
<ResourceParams name=&quot;jdbc/conn3&quot;>
...
</ResourceParams>
<ResourceParams name=&quot;jdbc/conn4&quot;>
...
</ResourceParams>
<ResourceParams name=&quot;jdbc/conn5&quot;>
...
</ResourceParams>
</Context>
<Context className=&quot;org.apache.catalina.core.StandardContext&quot; cachingAllowed=&quot;true&quot; charsetMapperClass=&quot;org.apache.catalina.util.CharsetMapper&quot; cookies=&quot;true&quot; crossContext=&quot;false&quot; debug=&quot;5&quot; displayName=&quot;Application 2&quot; docBase=&quot;./autobid&quot; mapperClass=&quot;org.apache.catalina.core.StandardContextMapper&quot; path=&quot;/autobid&quot; privileged=&quot;false&quot; reloadable=&quot;false&quot; swallowOutput=&quot;false&quot; useNaming=&quot;true&quot; wrapperClass=&quot;org.apache.catalina.core.StandardWrapper&quot;>
<Logger className=&quot;org.apache.catalina.logger.FileLogger&quot; debug=&quot;9&quot; directory=&quot;logs&quot; prefix=&quot;localhost_autobid.&quot; suffix=&quot;.txt&quot; timestamp=&quot;true&quot; verbosity=&quot;4&quot;/>
<Resource name=&quot;jdbc/conn1&quot; auth=&quot;Container&quot; scope=&quot;Shareable&quot; type=&quot;javax.sql.DataSource&quot;/>
<Resource name=&quot;jdbc/conn2&quot; auth=&quot;Container&quot; scope=&quot;Shareable&quot; type=&quot;javax.sql.DataSource&quot;/>
<Resource name=&quot;jdbc/conn3&quot; auth=&quot;Container&quot; scope=&quot;Shareable&quot; type=&quot;javax.sql.DataSource&quot;/>
<ResourceParams name=&quot;jdbc/conn1&quot;>
...
</ResourceParams>
<ResourceParams name=&quot;jdbc/conn2&quot;>
...
</ResourceParams>
<ResourceParams name=&quot;jdbc/conn3&quot;>
...
</ResourceParams>
</Context>
 
i've got a question, rather that an answer, but maybe once i have the answer, i will be able to help.
we are also using the db pooling, and it works fine if i call a class for db connection from a jsp, but the problem starts when i call the same class from another class within my web-inf/classes/etc folder. any suggestions on how to avoid that? the error is something of the sort ... is not bound to this context?
Thanks,
Alex
 
the one change i found is


you have written

Context ctx = (Context) new InitialContext().lookup(&quot;java:/comp/env&quot;);


write

Context ctx = (Context) new InitialContext().lookup(&quot;java:comp/env&quot;);

notice that u have written java:/comp/env
it should be java:comp/env
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top