This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes jndi in j2se? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "jndi in j2se?" Watch "jndi in j2se?" New topic
Author

jndi in j2se?

pooja jain
greenhorn
Ranch Hand

Joined: Jan 12, 2005
Posts: 213
can we use jndi in j2se? if yes, where will we configure resources?

thanks.


:d
Masoud Kalali
Author
Ranch Hand

Joined: Jul 08, 2004
Posts: 531

Pooja, It depends on your use case, JNDI is an standard interface for accessing Directory servers, You can use this interface in J2SE or J2EE code.
In J2EE when you initialize the context, usually you will not pass any argument as it is a managed environment and your container knows how to initialize the context for you.
But when we are trying to access a directory server from a none managed environment we will need to provide some information about your Directory server address, port, context factory, security credentials, etc.

for example:




Masoud Kalali
Software Engineer - My Weblog - GlassFish Security
Lave Kulshreshtha
Ranch Hand

Joined: Oct 21, 2007
Posts: 106
Masoud is right.
JNDI is actually is service which runns on application server. In order to access this service from j2se one need to use InitialContext interface, this interface needs the location (for e.g localhost) and port (for e.g. 3700) of JNDI service.
Hashtable properties = new Hashtable(2);
properties.put(Context.PROVIDER_URL,"iiop://127.0.0.1:3700");

Please note only by providing the this information in a j2se program will not work. You also need to include some more libraries to your j1se project.

-Lave


SCJP 1.4, SCWCD 1.4, SCBCD 1.3, ITIL V3 Foundation Certification
pooja jain
greenhorn
Ranch Hand

Joined: Jan 12, 2005
Posts: 213
Originally posted by Masoud Kalali:
Pooja, It depends on your use case, JNDI is an standard interface for accessing Directory servers, You can use this interface in J2SE or J2EE code.
In J2EE when you initialize the context, usually you will not pass any argument as it is a managed environment and your container knows how to initialize the context for you.


right. like this way:

InitialContext ic = new InitialContext();


But when we are trying to access a directory server from a none managed environment we will need to provide some information about your Directory server address, port, context factory, security credentials, etc.

for example:





what is directory server? how can i make one on my system?

suppose i have one directory server on my system running at port 1000. then first property would be:

properties.put(Context.PROVIDER_URL,"iiop://localhost:1000");

right?

and what is second property? why its required?

why in managed environment we dont need to specify location for directory server?

too many questions. but please answer. thanks in advance.
Lave Kulshreshtha
Ranch Hand

Joined: Oct 21, 2007
Posts: 106
here directory service will be JNDI service. The JNDI service is available on application server.

In order to use properties in a non managed env, please refer to your application server documentation. Every application server has their own classes and port number to run directory services.

Which application server you are using.

-Lave
pooja jain
greenhorn
Ranch Hand

Joined: Jan 12, 2005
Posts: 213
Originally posted by Lave Kulshreshtha:

In order to use properties in a non managed env, please refer to your application server documentation. Every application server has their own classes and port number to run directory services.

Which application server you are using.

-Lave


i m confused now. non-managed env means j2se means no server. right?


i want to use jndi in j2se so no server available. what to do?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31054
    
162

Originally posted by pooja jain:
i m confused now. non-managed env means j2se means no server. right?

Yes, but a regularly non-managed Java program can still make calls to a server. One case is to point to a server's JNDI.

Originally posted by pooja jain:
i want to use jndi in j2se so no server available. what to do?

Why do you want to use JNDI? Are you trying to share a resource between programs? If so, something has to host the JNDI directory. If not, what benefit of JNDI are you trying to benefit from?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Lave Kulshreshtha
Ranch Hand

Joined: Oct 21, 2007
Posts: 106
You can use JNDI in j2se, but at the same time JNDI is a service that is available on server.

Can you please provide details of your requirement, why do you want to use JNDI in a core java program, then possibly we would be able to help you in right direction.

-Lave

Originally posted by pooja jain:


i m confused now. non-managed env means j2se means no server. right?


i want to use jndi in j2se so no server available. what to do?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jndi in j2se?