Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HeadFirst EJB p.57 JNDI call problem

 
Frederic Filiatrault
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I'm getting an error with the example on page 57. I`ve looked to other thread and everybody talk about the classpath but I don`t think this is the problem. I tried it out manually to make sure :

C:\filiatr\SCBCD\projects\advice>java -cp c:\Sun\AppServer\lib\j2ee.jar;AdviceAppClient.jar;. AdviceClient

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at AdviceClient.main(AdviceClient.java:16)

Any Idea ?
 
alzamabar
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a know issue. The hint is that the component interface business method should be renamed into something else. It's just enought to look at other posts or to make a search in this forum to find the solution. This is what I did anyway.

Marco
 
Frederic Filiatrault
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already made a LOT of search before bothering with this subject.

It is more complicated than that I think. I saw the thread talking about the coflicting name "advice". My method's name is "tata", so no problem with this one.

Other thing... I seems that it needs a that the JNDI property "Context.INITIAL_CONTEXT_FACTORY" to be set up.

I event try to use the tutorial from SUN with deploying an Client App with EJB ref, but, same problem : NO INITIAL CONTEXT.

I'm using J2EE 1.4 (don't tell that it the problem...)
My classpath is : c:\Sun\AppServer\lib\j2ee.jar;.

thk for your help !
 
Frederic Filiatrault
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again,

Think the better way to solve a problem is by yourself ! hehehehe

Ok, found the problem. Listen carefully, like I said, not much info on the others threads about that.

Main reason : Version J2EE 1.4 is significatively different in deployment with J2EE 1.3.

You have to build an client application with the deploy tool and do a EJB ref to the Entreprise Bean.

NO INITIAL CONTEXT IS NECESSARY (sorry for capitals, it is important)

The code in the HeadFirst EJB book is GOOD but, like it says in ERRATA, don't use the name "getAdvice()" for the method but something different as "getMessage()" (There's a conflict between the Home Interface Name and something I don't remember. For more info, consult this web site, I found the explanation here).

I strongly suggest that you follow the J2EE Tutorial for deploying the Client Application (very easy), the part before is identical to the book.

Here's the HREF : http://java.sun.com/j2ee/1.4/docs/tutorial/doc/EJB4.html

OK, two last points :

1) As I'm writing this, the web page EJB4.html from SUN Web site is HTTP 404. Try it out ! EJB3.html and EJB5.html are there, but not 4.

2) Beware that the client application to be WITHIN the application (Sounds stupid but happened to me, lost few hours trying to find out with the EJB ref link wasn't there...)

Hope this will help someone else in the future.

Writing me up if you have problems, I'll get back to you.
[ August 02, 2004: Message edited by: Frederic Filiatrault ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic