on 02-02-2005 11:13 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bhavik,
please, follow the link of Davids struggle, and in addition /thread/26033 [original link is broken]
All these small NoClassDefFoundError's are really easy to solve when you take care about what's in your classpath. You have enough tools at hand to check if the class is there, and if not, put it into the classpath.
We shouldn't have the same three-page-discussion twice a week when it's all written down...
Best regards
Detlev
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bhavik,
I wrote
> it is probable that you don't have
> com.sap.engine.services.jndi.InitialContextFactoryImpl
> within your runtime classpath.
Must now read as
> it is sure that you don't have
> com.sap.engine.services.jndi.InitialContextFactoryImpl
> within your runtime classpath.
The first step is straight forward, it's just a question if you use J2EEClient.jar or pick up the needed JARs by yourself.
Hope it helps
Detlev
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bhavik,
first, to make it more easy for everyone reading this, the link to David's struggle:
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
92 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.