It's not a secret anymore!
The moose likes EJB and other Java EE Technologies and the fly likes Initial Context Factory error with JBoss Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Initial Context Factory error with JBoss" Watch "Initial Context Factory error with JBoss" New topic

Initial Context Factory error with JBoss

Craig Gaffney

Joined: Mar 30, 2004
Posts: 15
G'Day all,
I am trying to do a simple JBoss EJB (Hello World), and access it via a java client. It's based of an example in Java2 Unleashed, which uses WebLogic (I don't have on my network). Both client and server are on the same machine (currently), but I am getting some problems.

I get the following error message

Cannot instantiate class: org.jboss.naming.HttpNamingContextFactory
javax.naming.NoInitialContextException: Cannot instantiate class: org.jboss.naming.HttpNamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jboss.naming.HttpNamingContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(
at javax.naming.InitialContext.getDefaultInitCtx(
at javax.naming.InitialContext.init(
at javax.naming.InitialContext.<init>(
at com.rags.ejb.simple.SimpleEJBClient.main(
Caused by: java.lang.ClassNotFoundException: org.jboss.naming.HttpNamingContextFactory
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClassInternal(
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(
at com.sun.naming.internal.VersionHelper12.loadClass(
at javax.naming.spi.NamingManager.getInitialContext(
... 4 more

Now, I this is the code in the client that is failing

Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.HttpNamingContextFactory");
h.put(Context.PROVIDER_URL, "https://localhost:8443/invoker/JNDIFactory");

//lookup jndi initial context
Context initial = new InitialContext(h);
Context ctx = (Context)initial.lookup("java:comp/env");

It seems like I am using the wrong context values, but I cannot find out what I should have there. Can anyone point me in the right direction?

BTW, I am using JBoss 3.2.5 on Mandrake 10.0, J2SDK 1.4.2_05. I think that's all for the environment....

Thanks in advance for your help,

alen agmon

Joined: Sep 22, 2004
Posts: 11
there are few things that can be wrong here:
are u writing an "application client" or a test class?
one way to solve it , if u write a test class is to include in your compilation's classpath a jndi.prperties file contains the naming stuff ,


java.naming.factory.initial = org.jnp.interfaces.NamingcontextFactory
java.naming.factory.url.pkgs= org.jboss.naming rg.jnp.interfaces

include that as in your classpath and throw all those Properties.put stuff from your code.

about the context in the code the correct way is :
(this is how you call it from a servlet for example)

context ctx = new InitialContext();
Object ref = ctx.lookup("java:comp/env/ejb/yourEjbHome");
EjbHome home = (EjbHome)PortableRemoteObject.narrow(ref,EjbHome.class);
Ejb ejb = home.create();
Craig Gaffney

Joined: Mar 30, 2004
Posts: 15
G'Day Alen,
I am writing an application client, not a test class.

The code is exactly as taken from the example from the Java2 Unleashed book, so if it isn't correct, it's their fault not mine.

As a possibility, could I have missed out a class file or jar file that should have been included in the client application? I wouldn't be surprised if that happened.

Anyway, thanks for the help so far.

alen agmon

Joined: Sep 22, 2004
Posts: 11
check out :
alen agmon

Joined: Sep 22, 2004
Posts: 11
and this example :

and another one from source forge:
I agree. Here's the link:
subject: Initial Context Factory error with JBoss
jQuery in Action, 3rd edition