Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Still having problem with my first EJB3

 
Mamadou Touré
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm still confused with how to interact with the JNDI, here is my simple code to display hello, so could someone tell me what's wrong ?

1 - error message tha I got
Exception in thread "main" 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(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at sourceClient.HelloClient.main(HelloClient.java:21)

2 - My EJB class and interface:





3 - My EJB client
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

from a quick look your examples looks alright!

The problem is the JNDI lookup. You have to know the right lookup name and you most probably have to specify some system parameters which tell the client for example on which IP address and port it may connect to a JNDI provider.

Both of these things may depend on the application server (at least with EJB 3.0) you're using! So perhaps you can tell us which server it is or you can search yourself on the internet which are the correct settings for your server!

Marco
 
Mamadou Touré
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,

I'm using Glassfish server

Do I have to setup something on the server ?
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

from the header of your code fragments I guess you used NetBeans to create the project. Perhaps it's the easiest way to understand the problem by having a look at this tutorial. In particular the section "Creating a Java Stand-Alone Client" will be helpful as it describes how to setup the JNDI parameters with a "jndi.properties" file on the classpath ;-)

Additionally it could be useful for debugging to show what's in the JNDI lookup of Glassfish as described here.

Marco
 
Sai Surya
Ranch Hand
Posts: 463
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marco,

Perhaps you can try using name attribute for your @Stateless annotation and use that name in the JNDI look up. It worked for me in Glashfish app. server.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic