• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A question about NoInitialContextException:

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
avseq anthoy
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
reply
    Bookmark Topic Watch Topic
  • New Topic