File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes Query reg Tomcat connection pool Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Query reg Tomcat connection pool" Watch "Query reg Tomcat connection pool" New topic

Query reg Tomcat connection pool

Sakthivelmurugan Kg

Joined: Aug 07, 2009
Posts: 3
Hi All,

Can i run a stand alone java class(but which is included in my web application) to get a datasource for the tomcat connection pool? when i try to run the java cliass(its main method), i am getting the following exception:

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

Can someone help me to solve this error?

Thanks & Regards,
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

I don't know what you mean by running a stand alone java class. Normally, classes in a web application are invoked by the application server. If you're trying to do something like this:

Then you're not really running "in" the webapp, just using the war as though it was a jar. And, since the JNDI registry is built and controlled by the Tomcat server, but you're not running in the server, there's no registry to be found.

An IDE is no substitute for an Intelligent Developer.
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

I've done this kind of thing to get to Weblogic EJB's from stand-alone applications. One has to specify an initial context factory, server URL and server credentials.
I don't know if Tomcat makes it's JNDI accessible like Weblogic does. Google pointed me to this guy who looks like he's got a number of the settings right, but still cannot look up a JNDI resource.

[How To Ask Questions On JavaRanch]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

As far as I know, Tomcat doesn't publish its JNDI registry on a port. At least by default. So the only way to get the root context is via the Tomcat internal classpath.

WebLogic would have had problems not publishing its registry, since that's how remote apps lookup the EJBs. Since Tomcat doesn't support EJBs, they don't need that ability.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63866

"Sakthivelmurugan Kg", please check your private messages for an important administrative matter.

Also, please use real words when posting to the forums. Abbreviations such as "reg" in place of "regarding" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please read this for more information.

JavaRanch sheriff

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Query reg Tomcat connection pool
It's not a secret anymore!