on 11-12-2004 3:22 PM
Hi,
I'm facing a little problem: trying to implement a plain Java client for acessing an CMP Entity Bean I keep getting
the following error:
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 javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:652)
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.test.SimpleEarClient.main(SimpleEarClient.java:65)
Caused by: java.lang.ClassNotFoundException: com.sap.engine.services.jndi.InitialContextFactoryImpl
...
As I am not a very experienced developer, I don't quite understand what exactly can be the reason
for this. (Maybe there is some additional reference missing?)
The code for it:
...
private static String userName = "userName";
private static String password = "password";
private static String hostUrl = "localhost:port";
private static String initContextFactory = "com.sap.engine.services.jndi.InitialContextFactoryImpl";
private static final String BIKECMP_LOOKUP_STRING = "sap.com/SimpleEAR/BikeCMPBean";
public static void main(String[] args) {
//Build the InitialContext environment properties
Properties ctxProp = new Properties();
ctxProp.put(Context.INITIAL_CONTEXT_FACTORY,initContextFactory);
ctxProp.put(Context.PROVIDER_URL, hostUrl);
ctxProp.put(Context.SECURITY_PRINCIPAL, userName);
ctxProp.put(Context.SECURITY_CREDENTIALS, password);
BikeCMP bean = null;
String xmlTest;
try{
Context ctx = new InitialContext(ctxProp);
BikeCMPHome home = (BikeCMPHome) ctx.lookup(BIKECMP_LOOKUP_STRING);
bean = home.findByPrimaryKey(new Integer(1));
xmlTest = bean.getXml();
System.out.println("Printing the result of the query: " + xmlTest);
}
...
Maybe you can help me on that.
Thanks!
Beata
Hi Beate,
I assume, by "simple Java client" you mean a Java client, that should act as a remote client to your EJB.
You would have to create the Context with the "right" credentials. The port should be the RMI-port (<http_port> + 4). Additionally, in the classpath of your client, you should have the classes needed for casting and obtaining the relevant factories (InitialContextFactory and such). The engine defines a so called "client.jar", which you should download from your engine (basicly by copying it from the engine's file system) and putting it in your classpath.
Let me know if you need additional help on this.
Regards, Goran
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi all
I am facing a "NoInitialContextException" problem while ejb lookup.
I want to lookup a ejb in the same server as of my java client.
I have added all the required jars and followed each step as in the forums.Is there any other way out.
<u>Error:</u>
<i>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 javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:652)
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.chevron.ccs.mapping.Mapping.main(Mapping.java:96)
Caused by: java.lang.ClassNotFoundException: com.sap.engine.services.jndi.InitialContextFactoryImpl
at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:219)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)
... 4 more</i>
Thanks in Advance
DhanyaR Nair
Hi Dhanya,
I think this link should solve your problem.
http://help.sap.com/saphelp_nw04s/helpdata/en/c1/302c4142aef623e10000000a155106/frameset.htm
This link clearly explains that there are only few possible reasons for this NoInitialContextException .Chec it out and resolve your exception.
Hope this helps.
Please reward points for helpful answers.
Thanks and regards
Deepa
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.