Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » J2EE Interest »

Re: I can't obtain the reference to an EJB!

prashanth tr

2006-02-16

Replies:

I think u might have not added the jar file containg   org.jnp.interfaces.NamingContextFactory
and that is what it is complainig about.
u can find that jar in ur application server. if u are using jboss then u can find that
jar file in X:\jboss-4.0.3SP1\client\jboss-client.jar
just add that jar to ur poject or classpath
 
Thanks
Prashanth T R

 



 
On 2/16/06, Reydel <rleonm@facinf.uho.edu.cu> wrote:

   Hi, I'm a new one working with J2EE. I'm developing an application and I need to access the EJBs from my client (a Java application).

   This is the code of my client (a test one):

 


package clients;

 
import java.util.Properties;
import javax.rmi.PortableRemoteObject; 

import javax.naming.*;

 
class Client
 {

    public static void main(String[] args)
    {
       Properties env = new Properties();

       
       
// Define properties and JNDI names lookup location.

       env.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");

       env.setProperty("java.naming.provider.url",  "localhost:1099");

       env.setProperty("java.naming.factory.url.pkgs",  "org.jboss.naming");

 
       
try
       {
          // Bring the name context

          InitialContext jndiContext = new InitialContext(env);
          System.out.println("Contexto Disponible");

          
          
// Bring the referente to the EJB
          Object ref  = 
jndiContext.lookup("Calculo");
          System.out.println("Se encontrĂ³ Referencia del EJB!");
          

          // Bring the referente to the "Home Interface "

          InteresesHome home = (InteresesHome) 
          PortableRemoteObject.narrow (ref, InteresesHome.class
);
 

          // Create an object from the "Home Interface"
          Intereses interes = 
home.create();
 

          // Call the function 
          System.out.println
("Interés de 10,000 Capital, a tasa 10%, bajo 2 plazos anuales:");
          
System.out.println(interes.calcularInteres(10000, 0.10, 2));

       }
       catch(Exception e)

       {
          System.out.println(
e.toString());
       }

    }
 }

 
 

When I execute this, there is an error. It says :   javax.naming.NoInitialContextException : Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException : org.jnp.interfaces.NamingContextFactory]


 
Would some of you be so kind to help me fixing that? What sould I do?

 

 

 

=========================================================================== To unsubscribe, send email to listserv@java.sun.com and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@java.sun.com and include in the body of the message "help".


=========================================================================== To unsubscribe, send email to listserv@java.sun.com and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@java.sun.com and include in the body of the message "help".

©2008 junlu.com - Jax Systems, LLC, U.S.A.