Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

where is jndi.properties for my ejb client applcication?

Posted on 2004-10-23
17
Medium Priority
?
252 Views
Last Modified: 2013-11-24
I have deployed a simple ejb on the Sun Application server on my computer where it is located on :localhost:8080

now i want to write a client application to test and use that ejb but when i cann InitialContext's lookup method it throws a "NoInitialContext" exception and says that : need to specify class name in environment or system property or as applet parameter or application resource file : java.naming.factory.initial

I searched all of my hard drive and could not find a "jndi.properties" which i think is the solution for my problem .

What should i do now for running my client application?
0
Comment
Question by:somebody314
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
17 Comments
 
LVL 3

Expert Comment

by:aviadbd
ID: 12391697

Well, you could always just add it up to the Hashtable passed to the InitialContext class on construction.

Besides that, you could read this, about application resource files: http://java.sun.com/j2se/1.4.2/docs/api/javax/naming/Context.html#RESOURCEFILES

AviadBD.
0
 

Author Comment

by:somebody314
ID: 12391742
but wgat should i add to the hashtable ? which items?
0
 
LVL 3

Expert Comment

by:aviadbd
ID: 12391826

"java.naming.factory.initial", for example. :)

For example, if you're using WebLogic's container, use

env.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");

and then pass "env" to the InitialContext's ctor.

AviadBD.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 3

Expert Comment

by:aviadbd
ID: 12391830

BTW, "java.naming.factory.initial" is also set as a static value of interface Context, so you could also do:

env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");

AviadBd.
0
 

Author Comment

by:somebody314
ID: 12398035
But how can it find the JNDI server on the application server? i have not set the IP of the server and it's port in the client program , so how can it find where the application server is placed?
0
 
LVL 3

Expert Comment

by:aviadbd
ID: 12404319

Its not where its placed, its the factory which creates it. It is contained in the jar file supplied with the application server.. You should have documentation with the application server.

PS, if you're using Sun's application server, its already configured to it defaultly.

Aviad.
0
 

Author Comment

by:somebody314
ID: 12407875
I have deployed my ejb and when i run this :
Context ic=new InitialContext();
ic.lookup("java:comp/env/ejb/Hello");

or any other string in lookup function a NoInitialContext exception is thrown . even when i construct the intialcontext using Syste.getProperties()

Now what should i do?
I think i have to set some of these variables in a Hashtable and pass it to the initial context's constructor but i do not know the values i shoudl use .
-> java.naming.factory.initial
-> java.naming.provider.url
0
 
LVL 3

Expert Comment

by:aviadbd
ID: 12407987

What is your application server? Where do you deploy the EJBs? I'll help you look for the values.

Aviad.
0
 

Author Comment

by:somebody314
ID: 12418933
the problem is solved :
I  should place these two items in the environment hashtable or put them in a jndi.properties file and place it in the root directory of my project :
java.naming.provider.url=iiop://localhost:3700
java.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory
0
 
LVL 3

Expert Comment

by:aviadbd
ID: 12421755

Well, good that its solved.

Thats actually what I asked you - Where are the EJBs deployed. But by your resolution, it seems that you use a CORBA Context?

Aviad
0
 

Author Comment

by:somebody314
ID: 12517134
I think si , How can i use JNDI instead?
0
 
LVL 3

Expert Comment

by:aviadbd
ID: 12517724

Well, there are multiple ways... JNDI can be used to reach a Directory services (Like Active Directory or iPlanet) or even a file system like NTFS, given the right drivers.

Aviad.
0
 

Author Comment

by:somebody314
ID: 12530619
Ok , but how can i use it ? I have installed Sun Application Server completely so what should i put as a value for initial factory and provider url in the hashtable passed to the initialcontext?
0
 
LVL 3

Accepted Solution

by:
aviadbd earned 450 total points
ID: 12541712

The Sun Application Server works with IIOP which is basically ORBs (CORBA). So, you would use

// Set initial context and URL properties
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,
  "com.sun.jndi.cosnaming.CNCtxFactory");
env.put(Context.PROVIDER_URL, "iiop://host_name:9010");

And then create the context:

Context ctx = new InitialContext(env);

Ofcourse, you could put these properties in a properties file.

Aviad.
0
 
LVL 3

Expert Comment

by:aviadbd
ID: 12541718
0
 

Author Comment

by:somebody314
ID: 12541748
thanks very much.
as i wrote in a previous comment in 10/26/2004 11:43PM PDT
the problem is solved.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question