Link to home
Create AccountLog in
Avatar of CIPL-Senthil
CIPL-Senthil

asked on

J2EE 1.4 vs JNDI

Hi Experts,

I have deployed an simple EJB in Sun's J2EE 1.4 server. When I try to connect through the client application, it is throwing the following error:

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

Could you please help.

Regards
Vijay T. Prabakar
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Can you post your code for connection?
Avatar of CIPL-Senthil
CIPL-Senthil

ASKER

Hi Experts,

Here is my code for connection:

                  Context initial=new InitialContext();
                  Context myEnv = (Context)initial.lookup("java:comp/env");
                  Object objref=initial.lookup("ejb/TemperatureEJB");
                  home=(TemperatureHome) PortableRemoteObject.narrow(objref,TemperatureHome.class);
                  Temperature degreeConverter=home.create();

Regards
Vijay T. Prabakar
Try:

                  Context initial=new InitialContext();
                  Object objref=initial.lookup("java:comp/env/ejb/TemperatureEJB");
                  home=(TemperatureHome) PortableRemoteObject.narrow(objref,TemperatureHome.class);
                  Temperature degreeConverter=home.create();
No Change. Reporting the same error.
Ahhh, yeah...forgot we need to set up the properties so that JNDI knows what and were to go...

What is the server you are using?  Where did you get it from?

I know for JBoss, I use:

      java.util.Properties JNDIParm = new java.util.Properties() ;
      JNDIParm.setProperty( InitialContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory" ) ;
      JNDIParm.setProperty( InitialContext.PROVIDER_URL, "jnp://localhost:1099" ; ) ;
      JNDIParm.setProperty( InitialContext.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces" ) ;

THEN, get the context:

      ctx = new InitialContext( JNDIParm ) ;

But your properties might need to be different to those...

Tim
Hi Experts,

Is there any possibility to see the regisered JNDI name for the deployed application. In the Deployement Tool, if I select the deployed bean and choose the Sun-Specific Settings option, it is showing the Component is TemperatureEJB and the JNDI name as TemperatureEJB.

My concern is about why we are specifying the JNDI name as: "java:comp/env/ejb/TemperatureEJB"

Please advice.

Regards
Vijay T. Prabakar
Hi TimYates,

I am using Sun's J2EE 1.4 Application Server.

Regards
Vijay T. Prabakar
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Hi Tim,

Otherwise could you tell me how to deploy the same in JBoss Application Server. I am having "jboss-4.0.0RC1".

Regards
Vijay T. Prabakar
Just copy your EJB jar into jboss/server/deploy
Compile your client (with the jboss/client jars included)
Set up the context as above

and it should run...
Try with "com.sun.jndi.cosnaming.CNCtxFactory" as the initial context factory.

>> My concern is about why we are specifying the JNDI name as: "java:comp/env/ejb/TemperatureEJB"

You can store these values (class-name, JNDI-name, etc) in a properties-file and load from there.