aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes A question about NoInitialContextException: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "A question about NoInitialContextException:" Watch "A question about NoInitialContextException:" New topic
Author

A question about NoInitialContextException:

avseq anthoy
Ranch Hand

Joined: Apr 27, 2004
Posts: 104
The following code can work in JSP , but it can't work when I write in a class.
Are there any wrong of my code and where need change?
Thanks in advance


The error message listed below


My Way,My Pace
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

When you say it doesn't work in a class, what do you mean?
Are you calling your class as a standalone Java program from the command line?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
avseq anthoy
Ranch Hand

Joined: Apr 27, 2004
Posts: 104
Yes , I deploy the class on Tomcat and calling my class as a standalone Java program from the command line.
Becase I want get JNDI through my class.
What can I do if I want to use JNDI through class not in JSP?
[ July 19, 2007: Message edited by: avseq anthoy ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you go to our Code Barn page, there is a mock JNDI implementation that can be used for doing this.

With it, all you need to do is add one line to your main method to insure that there will be an InitialContext waiting for the other methods in your class that need it.

http://www.javaranch.com/codebarn.jsp
avseq anthoy
Ranch Hand

Joined: Apr 27, 2004
Posts: 104
I change my cod as below, but it still can't work.
Are there any wrong with the code?

Error message as below:
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

When you run your code from the JSP, the container is providing the necessary environment for you to get connections via JNDI.

Since your problem is that you can't get JNDI working from outside the container, this is no longer a JSP issue.

Moving to Other Java APIs.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10266
    
168

Originally posted by avseq anthoy:
Error message as below:
Exception in thread "main" javax.naming.NameNotFoundException: java:/comp/env


The java: namespace is not available outside the application server JVM. Since you are looking up a object in the JNDI tree from a standalone java class, you will have access to only the global jndi namespace objects.


[My Blog] [JavaRanch Journal]
 
Don't get me started about those stupid light bulbs.
 
subject: A question about NoInitialContextException: