Before you get the InitialContext, a JNDI server has to be running. If you're
working with an appserver, the appserver typically starts one. It is also possible
to start one yourself. Either way, you need to know the name of the initial context
factory, and the location of the JNDI provider (aka server).
Here are properties that control this:
#this is the name of the factory
java.naming.factory.initial
#this points to the machine that provides it. The machine doesn't have to be local.
java.naming.provider.url
You can either set these up programmatically using a Properties object,
or put them in a file called jndi.properties and make sure the file is in
your class path.
if you use the jndi.properties approach you can do this:
InitialContext ic = new InitialContext();
You can even do this as long as the properties have been loaded or set
by any piece of code that runs before your code (in the same VM). The
naming package will look for these properties to be set somehow, otherwise
it will look for em in jndi.properties.
if you use the programmatic approach, you'd do something like this:
Properties props = new Proeperties();
props.setProperty( "java.naming.factory.initial", "whatever");
props.setProperty( "java.naming.provider", "localhost");
InitialContext ic = new InitialContext( props );
Note that you can use Hashtable/put if you prefer it. Properties is just a
derivation of Hashtable with a few nice methods for property related stuff.
You could have two JNDI servers running, but to get the InitialContext
you want you need to make sure that you use the properties described
above accordingly.
hope this helps.
"Kenneth D. Litwak" wrote:
> I have have two naming system questions
>
> 1. When I make the call INitialContext ctx = new INitialContext();
> where is that InitialContext object, on my machien or on the server (assuming
> the real situation that my sever is not my client as well)? Where is the info
> on where the InitialContext is located stored? In my client-sdie jar?
>
> 2. How does a client know where JNDI is located? What if I wanted to have
> two naming services,each accessible from JNDI? COuld one client access both and
> if so, how?
>
> Thanks.
>
> Ken
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff EJB-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".