Skip to Content
author's profile photo
Former Member

Accessing EJB from console application from remote client

Hi everybody,

I have developed one EJB which contains onne Session bean for business logic and one Entity bean for database access.

Now i want to access this EJB from my Console application.

I have wrriten following code for getting context and creating home object of bean.

jndictxprop.put(Context.INITIAL_CONTEXT_FACTORY,

"com.sap.engine.services.jndi.InitialContextFactoryImpl");

jndictxprop.put(Context.PROVIDER_URL,

"server:50004");

jndictxprop.put(Context.SECURITY_PRINCIPAL, "myLogin");

jndictxprop.put(Context.SECURITY_CREDENTIALS, "myPassword");

try {

Context jndicontext = new InitialContext(jndictxprop);

Object obj =(Object) jndicontext.lookup("StatefullBean");

EMP_StatefullHome home =(EMP_StatefullHome) javax.rmi.PortableRemoteObject.narrow(obj,

EMP_StatefullHome.class);

EMP_Statefull hello = home.create();

System.out.println(hello.GetDetails("720195").getEmp_id());

} catch (Exception e) {

e.printStackTrace();

}

But its giving exception

javax.naming.NoInitialContextException: Cannot instantiate class: com.lti.InitialContextFactoryImpl. Root exception is java.lang.ClassNotFoundException: com.lti.InitialContextFactoryImpl

at java.net.URLClassLoader$1.run(URLClassLoader.java:198)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:186)

at java.lang.ClassLoader.loadClass(ClassLoader.java:299)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)

at java.lang.ClassLoader.loadClass(ClassLoader.java:255)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:217)

at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)

at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)

at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)

at javax.naming.InitialContext.init(InitialContext.java:219)

at javax.naming.InitialContext.<init>(InitialContext.java:195)

at com.lti.bh.UserlistClient.mainClass.main(mainClass.java:37)

If anybody knows then pls help me.

Thank you,

Bhavik

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

6 Answers

  • Best Answer
    author's profile photo
    Former Member
    Posted on Feb 03, 2005 at 03:45 AM

    Hi Vladimir,

    I have refered your post. And i have done similar job in my project. I have added sapj2eeclient.jar file in classpath also. But now its giving Exception :

    java.lang.NoClassDefFoundError: com/sap/exception/IBaseException

    at java.lang.ClassLoader.defineClass0(Native Method)

    at java.lang.ClassLoader.defineClass(ClassLoader.java:502)

    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)

    at java.net.URLClassLoader.defineClass(URLClassLoader.java:250)

    at java.net.URLClassLoader.access$100(URLClassLoader.java:54)

    at java.net.URLClassLoader$1.run(URLClassLoader.java:193)

    at java.security.AccessController.doPrivileged(Native Method)

    at java.net.URLClassLoader.findClass(URLClassLoader.java:186)

    at java.lang.ClassLoader.loadClass(ClassLoader.java:299)

    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)

    at java.lang.ClassLoader.loadClass(ClassLoader.java:255)

    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)

    at java.lang.Class.forName0(Native Method)

    at java.lang.Class.forName(Class.java:217)

    at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)

    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)

    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)

    at javax.naming.InitialContext.init(InitialContext.java:219)

    at javax.naming.InitialContext.<init>(InitialContext.java:195)

    at com.lti.bh.UserlistClient.mainClass.main(mainClass.java:38)

    Exception in thread "main"

    May be my InitialContextFactoy value is wrong.

    I have specified InitialContextFactoy as :

    com.sap.engine.services.jndi.InitialContextFactoryImpl

    Is it right or not.

    What this value signifies and from where we can find this link?

    Thanks for your valueble help.

    Bhavik

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Bhavik,

      The InitialContextFactoy is correct.

      The sapj2eeclient.jar contains only the necessary classes from the J2EE Engine. Generally, you also need some external libraries like exception.jar and logging.jar which can be found in the /usr/sap/<SID>/<INSTANCE>/j2ee/j2eeclient dir too. Depending on what your client is doing, you may also need some of the J2EE API jars in that dir (e.g. ejb20.jar, servlet.jar, jta.jar, etc.)

      Hope this helps,

      Vladimir

  • Posted on Feb 02, 2005 at 11:29 AM

    Hi Bhavik,

    Please look at my topic : "Problem calling EJB under WAS 6.40 ".

    I had the same problem.

    You have to add some jars to your project classpath.

    But I still have problems doing lookup of an EJB.

    If you success calling an EJB, could you please tell me how.

    Thanks.

    Regards

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 02, 2005 at 11:51 AM

    Hi Bhavik,

    first, to make it more easy for everyone reading this, the link to David's struggle: Problem calling EJB under WAS 6.40

    Then, your problem this time seems to be how com.lti.InitialContextFactoryImpl comes here into the game?! You have set com.sap.engine.services.jndi.InitialContextFactoryImpl as the initial context factory, but somewhere the above given class must have been set on your machine.

    Anyhow, from the first glance at the stack trace, it is probable that you don't have com.sap.engine.services.jndi.InitialContextFactoryImpl withn your runtime classpath.

    Hope it helps

    Detlev

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Feb 02, 2005 at 11:52 AM

    I m facing the problem in InitialContextFactory in property of Context.

    I have specified property:

    jndictxprop.put(Context.INITIAL_CONTEXT_FACTORY,"com.sap.engine.services.jndi.InitialContextFactoryImpl" );

    but its giving exception :

    javax.naming.NoInitialContextException: Cannot instantiate class: com.sap.engine.services.jndi.InitialContextFactoryImpl. Root exception is java.lang.ClassNotFoundException: com.sap.engine.services.jndi.InitialContextFactoryImpl

    means there is problem in this initial context factory value.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Feb 02, 2005 at 11:56 AM

    oh i m sorry for message in first post. Atually exception is earlier one. Now i m giving correct exception here.

    javax.naming.NoInitialContextException: Cannot instantiate class: com.sap.engine.services.jndi.InitialContextFactoryImpl. Root exception is java.lang.ClassNotFoundException: com.sap.engine.services.jndi.InitialContextFactoryImpl

    at java.net.URLClassLoader$1.run(URLClassLoader.java:198)

    at java.security.AccessController.doPrivileged(Native Method)

    at java.net.URLClassLoader.findClass(URLClassLoader.java:186)

    at java.lang.ClassLoader.loadClass(ClassLoader.java:299)

    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)

    at java.lang.ClassLoader.loadClass(ClassLoader.java:255)

    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)

    at java.lang.Class.forName0(Native Method)

    at java.lang.Class.forName(Class.java:217)

    at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)

    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)

    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)

    at javax.naming.InitialContext.init(InitialContext.java:219)

    at javax.naming.InitialContext.<init>(InitialContext.java:195)

    at com.lti.bh.UserlistClient.mainClass.main(mainClass.java:38)

    I have refered the topic of David. And i m following in that direction only. But i m getting exception about Initial Context factory.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Feb 04, 2005 at 04:32 AM

    Thanks to everyone who helped me to solve my problem.

    I have added all required JAR files :

    Exception.jar, logging.jar.

    Now client runs sucessfully.

    Thanks alot once again.

    Add comment
    10|10000 characters needed characters exceeded